Quick Question...

Recently I reported a bug to PHP.net.

If you are using a PHP 5.x you will notice something very interesting… It no longer excepts mm-dd-YYYY, which is, in the U.S. anyway, common date format.

They told me that this isn’t a bug and just how it works now. I was more than a little displeased with this as I have written several applications that use the date format of mm-dd-YYYY and then use strtotime() to convert it then use date() to convert it into what MySQL excepts, which is dd-mm-YYYY.

Anyone else experience this or can say how they deal with date format conversions?

Not being from the US, I find the US-style date format rather illogical. Most logical would be YYYY-MM-DD, for sorting purposes. If you really want to input a US-style date format into a DATE or DATETIME type column in MySQL, perhaps STR_TO_DATE is an option. This allows you to use US-style (or any other style) date formats in your PHP and have MySQL resolve the actual stamp for you.

Personally I prefer the use of (GMT + 0) timestamps throughout my scripts, and use date() to display the desired format on the frontend. This is to make sure no ambiguous date expressions appear (03-05-2008 … is that May 3 or March 5?).

As illogical the US date format is, its where I live and the American public is my end user so that I is who I care most about. I hadn’t seen the STR_TO_DATE() before and I thank you for pointing out to me! I will certainly give that a try. The more I can do with the SQL the better!

Thanks again for the help!!

I’m not saying it’s wrong to use US style date format, just saying that it makes little sense logic-wise because the order in which the different elements are placed is off. The same goes for ‘our’ format: DD-MM-YYYY hh:mm:ss. It throws off less complex sorting methods (for example, daily logfiles with timestamps in their names on the filesystem get YYYY_MM_DD_filename.ext if I’d be the one deciding on it. Why? Easy sorting :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service