Convert MYSQL timestamp to time_t

I am writing a multi-threaded program that should be able to check if a string requires updating and acting accordingly.

I had problems using MySql's built-in date and time functions, so I decided to just save the lastupdate timestamp as an integer in the table. However, I am having problems converting this timestamp to time_t so that I can use the time functions with it.

Any help is greatly appreciated.

+4
source share
2 answers

The MySql timestamp data type can be saved as a number in the format YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD or YYMMDD.

On Unix and POSIX-compatible systems, time_t is usually an integer that represents the number of seconds since the start of the Unix era: midnight UTC on January 1, 1970.

In MySQL, you can use UNIX_TIMESTAMP () and FROM_UNIXTIME () converts functions between TIMESTAMP values ​​and Unix timestamp values.

Example query: SELECT Unix_Timestamp(Date_Entered) FROM Foo;

+7
source

Try FROM_UNIXTIME and TO_UNIXTIME and leave the dates in the database.

+4
source

All Articles