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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.