problem with dates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
UndpUndo
Forum Newbie
Posts: 7
Joined: Fri Sep 16, 2005 3:42 am
Location: UK

problem with dates

Post by UndpUndo »

this will hopefully be quite simple for someone however its giving me plenty of problems.

I have a timestamp(14) msql field that is being return from a query. The data in the field is 20051004165312.

I am using php'sd date("M d Y H:i:s", $row['dateAdded']) on the data return but it is producing a date: Jan 19 2038 03:14:07 which is way off. it should be something like OCt 04 2005 etc.

what am i doing wrong??[/i]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the "timestamp" used by the database does not correspond to the timestamp used by php. Try using DATE_FORMAT()
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

Alternatively, you can try this:

Code: Select all

date("M d Y H:i:s",  strtotime($row['dateAdded']));
strtotime() is a beautiful function. Read up on it :)

Note: It might not work with the timestamp you got, but it's worth a shot. If not, look into DATE_FORMAT() which is MySQL's function to format a date.
UndpUndo
Forum Newbie
Posts: 7
Joined: Fri Sep 16, 2005 3:42 am
Location: UK

Post by UndpUndo »

thanks for your help chaps

appreciated :)
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

As you can see with a little close-up on the "timestamp" you have on your DB: 20051004165312

2005/10/04 - 16:53:12; a date format.

Where a "real" UNIX timestamp would be the number of seconds passed since January 1st 1970. (or "71, cant remember exactly.)
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

pilau wrote:As you can see with a little close-up on the "timestamp" you have on your DB: 20051004165312

2005/10/04 - 16:53:12; a date format.

Where a "real" UNIX timestamp would be the number of seconds passed since January 1st 1970. (or "71, cant remember exactly.)
I think it was December 31, 1969, the beginning of the epoch.
Post Reply