date() keeps returning a date of 1969

While working with dates and times in PHP, you may run into a date() operation that outputs Wed, 31 Dec 1969 19:33:27 EST or something completely wrong.

Here's a scenario.

First of all, I needed this for an RSS feed for the <pubDate> tag. That's why I added the 00:00:00 or why it appears. Anyway, I want to convert a date that looks like 2007-10-17 into Wed, 17 Oct 2007 00:00:00 GMT where the 00:00:00 just comes along for the ride. date() will add that time just because there was no time associated with 2007-10-17.

Here's the bad code:

$old_date = "2007-10-17";
$new_date = date("D, j M Y H:i:s T",$old_date);

Here's the good code:

$old_date = strtotime("2007-10-17");
$new_date = date("D, j M Y H:i:s T",$old_date);

So basically, just don't forget to apply the function strtotime() to your date before running it through the date() function unless you're running the correct date string through date(). I only had to do this because I'm only dealing with the date, (I guess). I'm not quite sure the specifics, only the solution.

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.