Solved

Bad date formatting

Posted on 2007-11-14
3
313 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 500 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

679 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