Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.