Thread: mySQL Datetime

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    2

    mySQL Datetime

    Hi,

    How do you store and use an MySQL datetime variable in C?

    I can save it as a time_t variable, and if I do a printf using %s I can print it, and it looks like it should. But I want to compare the time between now and the time I get from my mySQL DB.

    If I use printf and %d, I only get 5 digits compared to 6 for my now value I create with time(NULL). And my DB dates are only a couple of days old (this after I have divided with 3600 to get it in hours instead of seconds).

    /Mattias
    Last edited by Creini; 10-22-2006 at 12:07 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Following calling time(), you need to use localtime() to get a 'struct tm', then use strftime() to format a time string.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MySQL libraries
    By csonx_p in forum C++ Programming
    Replies: 6
    Last Post: 10-02-2008, 02:23 AM
  2. can`t get mysql functions working in c++
    By markg85 in forum C++ Programming
    Replies: 4
    Last Post: 05-29-2006, 02:09 PM
  3. About C++ and MySQL or oether free database
    By xxxrugby in forum C++ Programming
    Replies: 18
    Last Post: 12-30-2005, 06:28 AM
  4. Get data from mysql and use in a system.
    By smaakage in forum Tech Board
    Replies: 3
    Last Post: 10-04-2005, 12:03 PM
  5. Get data from mysql and use in a system.
    By smaakage in forum C++ Programming
    Replies: 5
    Last Post: 10-02-2005, 01:25 PM