Jump to content

datetime or date and time?


sharkyJay

Recommended Posts

It is best to store the date and time as a unix timestamp in one field. Then when you get the timestamp out of the database you can use the date function to format the time stamp:
[code]date("d-m-y", $row['timestamp']);[/code]
Also you can easily compare dates too with timestamps.
A lot of people like UNIX timestamps, but be careful with them because they are messy when you have dates prior to January 1 1970.

It depends on what you are going to store, but quoting Barand:

[quote]@poirot

I was born in 1949 - try storing my date of birth in a UNIX timestamp.[/quote]

This was when I realized UNIX timestamps were not magical solutions.
Umm, thats a good point there poirot I always forget about unix timestamp will only work with dates prior to Jan 1 1970! But unix timestamp is okay for doings things such as logging when someone posts a message or logs in etc but not with DoB's
Be careful when trying to select records by date if you have both data and time elements the column

[code]2006-06-12 05:30:00
2006-06-12 09:30:00
2006-06-12 15:30:00

$date = date ('Y-m-d');

SELECT * FROM mytable WHERE datecol = '$date'[/code]

gives no rows.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.