Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Bad date formatting

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Number of hours between date in DB and now 8 21
How to display div value on input field value in php 11 52
XML extra information 8 28
Row insertion failed. Array 5 46
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

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