Jump to content

Weird Date happenings


SharkBait

Recommended Posts

Hi,

 

  I've been working with the following code for someone:

 

<?php

$news = mysql_query("SELECT *, DATE_FORMAT(NewsDate, '%m-%d-%Y %H:%i:%s') as myDate FROM News ORDER BY NewsDate DESC LIMIT 8") or die ("cant get em");

while($rows=mysql_fetch_array($news)){

$title=$rows["NewsTitle"];

$content=$rows["NewsText"];

$date = date('m-d-Y H:i s', strtotime($rows['myDate']) + 3600);

$author=$rows["author"];

?>

 

But what is happening when I echo $date it shows up at 11-23-2008 22:45:00. It should read 03-06-2007 22:45:00.

 

When I run the MySQL Query by itself within phpMyAdmin it returns the proper value for it which would be 03-06-2007 21:45:00.

 

Now when I run

<?php
echo date('m-d-Y H:i:s', strtotime('2007-03-06 22:45:00') + 3600);
?>

 

Locally it works fine.. but when the script runs on the remote location it doesnt work properly. I add 1 hour to compensate for the server being behind an hour (there is no control over server time due to it being a free webhost).

 

Any ideas??

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/41566-weird-date-happenings/
Share on other sites

If you're planning to feed the time into strtotime(), you should avoid m-d-Y format.  Try Y-m-d format instead.  It's much more computer friendly :)

 

Make the change in your mysql query.  You can reformat the date to m-d-Y later when you call date() in php.

Link to comment
https://forums.phpfreaks.com/topic/41566-weird-date-happenings/#findComment-201490
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.