Author Topic: Quick Question...  (Read 1744 times)

Ragster00

  • Senior Member
  • ****
  • Posts: 499
  • Karma: +0/-0
    • View Profile
    • Help with PHP?
Quick Question...
« on: March 06, 2008, 05:43:15 PM »
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?
-- I do what I can to help! :)
Not all code provided is meant to be a working, error free code. It is meant only as a guide.

Zyppora

  • Global Moderator
  • Senior Member
  • *****
  • Posts: 1401
  • Karma: +0/-0
    • View Profile
Re: Quick Question...
« Reply #1 on: March 07, 2008, 04:52:48 AM »
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?).
HAVE YOU TRIED DEBUGGING? Example code in this reply deliberately contains BUGS. PHP forum for beginners.

Ragster00

  • Senior Member
  • ****
  • Posts: 499
  • Karma: +0/-0
    • View Profile
    • Help with PHP?
Re: Quick Question...
« Reply #2 on: March 07, 2008, 04:30:51 PM »
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 do what I can to help! :)
Not all code provided is meant to be a working, error free code. It is meant only as a guide.

Zyppora

  • Global Moderator
  • Senior Member
  • *****
  • Posts: 1401
  • Karma: +0/-0
    • View Profile
Re: Quick Question...
« Reply #3 on: March 10, 2008, 04:10:41 AM »
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 :)
HAVE YOU TRIED DEBUGGING? Example code in this reply deliberately contains BUGS. PHP forum for beginners.