Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
computers:mysql_date_validation_and_conversion [2009/08/11 17:20]
daniel
computers:mysql_date_validation_and_conversion [2009/09/27 23:37]
daniel
Line 4: Line 4:
 Background reading: ​ http://​www.bigroom.co.uk/​blog/​dates-in-php-and-mysql Background reading: ​ http://​www.bigroom.co.uk/​blog/​dates-in-php-and-mysql
  
-Most easy is to store unix time in mysql using ''​time()''​ in php and use\\+Most easy is to store unix time in mysql using ''​time()'',​ ''​date()'',​ and ''​strtotime()''​ in php, such as following:
 <code php> <code php>
- 
 //unix timestamp, or use mktime() for another date/time than current time //unix timestamp, or use mktime() for another date/time than current time
-$unixtime = time();  ​+$unixtime = time();  ​//$unixtime is seconds from 1/1/1970, e.g. '​1249979071'​.
  
-//mysql datetime field, may omit $unixtime, i.e. date('​Y-m-d H:​i:​s'​);​+//mysql datetime field, may omit $unixtime ​if you need the current time-date
 $mysqldate = date( 'Y-m-d H:​i:​s',​ $unixtime );  $mysqldate = date( 'Y-m-d H:​i:​s',​ $unixtime );