Solved

Bad date formatting

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
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.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

759 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now