PDA

View Full Version : Displaying MySQL dates in PHP


ehmer
06-09-2003, 11:46 AM
I have several fields in my database that are of type 'date'. I want to display this in a browser, but the display seems to ignore the data in each field and uses the following dates only.

Jan 19 2038
jan 1 1970

I have been using PHP's date() function to display the data.

Appreciate any comments about what I'm doing wrong here.

David

michael.hd
06-09-2003, 12:15 PM
While i try and think of a solution, i can tell you this for sure,


When you put the data in to db you must put in in a specified format

'YYYY-MM-DD' or 'YY-MM-DD'.

there are more formats you can use but thats not the point. The point is that YOU specify the format when you enter the date in the db.
If you put it in as YYY_MM_DD, then that is how it will be stored, and you will be best to get it out the same way.

That 1970 date is actually zero so you must have put the date in incorrectly - hence mysql makes it zero and that is what is stored.

Did you format the date as dd-mm-yy or mm-dd-yy because these will equate to zero.

It must be year then month then day, but the dividing character can be anything.

(-) is safest as (/) and (_) have other meanings in mysql that may cause more problems for you.

the mysql manual at www.mysql.com will tell you all you need to know about date storage.

Hope this helps.