Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Bad date formatting

Posted on 2007-11-14
3
Medium Priority
?
346 Views
Last Modified: 2008-02-01
I am returning a date from my DB and using this to display it:

while($rs = mysql_fetch_object($query)) {
  echo "Game #".$rs->gamenum." - Date: ".
        date('M j, Y', $rs->gamedate)." (".$rs->gamedate.")";
}

It is returning this result:
Game #29 - Date: Dec 31, 1969 (2007-04-21 14:00:00)

Where is the Dec 31, 1969 coming from?
Should be returning Apr 21, 2007.
0
Comment
Question by:EddieShipman
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 2000 total points
ID: 20283839

while($rs = mysql_fetch_object($query)) {
  echo "Game #".$rs->gamenum." - Date: ".
        date('M j, Y', strtotime($rs->gamedate))." (".$rs->gamedate.")";
}
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 20283856
The date function needs a timestamp as the second argument.
strtotime() will turn the formated date to time stamp .

See
http://www.php.net/manual/en/function.strtotime.php
http://www.php.net/manual/en/function.date.php

0
 
LVL 26

Author Comment

by:EddieShipman
ID: 20283895
Thanks, I thought it was returning a timestamp. I don't know why I didn't think to do that.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question