Strange Problem With date() Function   

Sep 11th, 2011 // In: Php & MySQL // By: Comments 0

In short date(“Y-m-d H:i:s”) and date(“Y-m-d h:i:s”) were returning the exact same date and time with the same format. Both had 24 hour format but the lower-case “h” is meant to return 12 hour format. This date() function is a standard PHP function, not written by myself. I have no idea why this would happen. To get around the issue, I’ve changed my 12 hour formats to 24 hour so they are all the same.

Full Details of Problem

Someone reported that they could not create draft posts with Easy CSV Importer. The code looked great to me, it was working for months and no changes have been made to the scripts in question. So, I dismissed the scripts that I knew were written properly.

However, when I decided to double check the scripts I found something very unusual happening with the PHP date() function. When using the function like date(“Y-m-d h:i:s”) and as a parameter passed to function. The “h” was creating a 24 hour formatted time, when it is meant to create 12 hour. This actually worked out well for the post date, but I have no idea why PHP would then allow date(“Y-m-d h:i:s”) to return a 12 hour formatted date and time within the function that decides post status. Just makes no sense.

When using date(“Y-m-d H:i:s”) with uppercase “H” we get a 24 hour format as normal. I think this is what we should be using in most cases regarding dates in a post and I had it this way many weeks ago. Then some problems come up with it. In short date(“Y-m-d H:i:s”) and date(“Y-m-d h:i:s”) were returning the exact same date and time with the same format. When one should should 12 hour format and the other 24 hours.

I would love an explanation to how this has happened. I don’t have much time to look into it with detail but wanted to at least make post on my blog. My only guess right now is that using the date function like this was the cause eci_myfunction(date(“Y-m-d H:i:s”),$val).

Tags: -

Leave a Reply

You must be logged in to post a comment.