Solved

Bad date formatting

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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…

809 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