If I have a PHP string in the format YYYY-DD-MM and a timestamp in MySQL, is there a good way to convert between them?

I'm interested in doing comparisons between the date string and the MySQL timestamp. However, I'm not seeing an easy conversion. Am I overlooking something obvious?

This question and answers originated from www.stackoverflow.com
Question by (8/21/2008 5:26:23 PM)

Answer

Converting from timestamp to format:

date('Y-m-d', $timestamp);

Converting from formatted to timestamp:

mktime(0, 0, 0, $month, $day, $year, $is_dst);

See date and mktime for further documentation.

When it comes to storing it's up to you whether to use the MySQL DATE format for stroing as a formatted date; as an integer for storing as a UNIX timestamp; or you can use MySQL's TIMESTAMP format which converts a numeric timestamp into a readable format. Check the MySQL Doc for TIMESTAMP info.

Answer by

Find More Answers
Related Topics  php  mysql  time  timestamp  dates
Related Questions