Forum Moderators: open

Message Too Old, No Replies

MySQL Date() Function Question

         

fscanf

1:07 am on Jul 8, 2006 (gmt 0)

10+ Year Member



Hey all,

I have been inserting data into the database using the MySQL fucntion SYSDATE(). An example of the date that is stored in the database is 2006-07-05 19:37:15.

When i execute a select statement with Date(myDateField) in it, the output is returning 7/5/2006. I checked the MySQL manual at this page:

[dev.mysql.com...]

and by default, the value returned is 2006-07-05, the date part of what's in the database.

I know I can use DATE_FORMAT() to format the date to however I like it, but does anyone find this odd that by default the date is 7/5/2006 instead of 2006-07-05?

I am currently hosted on a shared webserver that is running MySQL 4.1.19-community-nt but could I be having this problem because I'm using an older version of MySQL?

Any help would be appreciated. Thanks!

txbakers

3:47 am on Jul 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How are you displaying the returned date? if it is in a web browser, then it might auto-format it if it looks like a date.

Run the query on the command line and see what you get.

Sometimes having the auto-format is nice, other times it's a royal nuisance, especially if you need to send that date back to the database.

I have three functions I use to convert the printed date back to sqlDate, depnding on the format shown. A lot of work dates are.