[SOLVED] Formatting DateTime

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
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

[SOLVED] Formatting DateTime

Post by AliasBDI »

I cannot seem to get this right. Am I coding it correctly?

Code: Select all

<?php $created = $row_userLIST['date_created']; echo strtotime("l dS of F Y h:i:s A", $created); ?>
Its returning a TIMESTAMP and another one is DATETIME fields. It is giving me '-1' and that is it.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

the way you have it you'll want to use date() instead of strtotime
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Worked!!

Post by AliasBDI »

Is there a shorter way of coding this? So I can apply the date() function to the echo of the $row rather than declaring the $row as a $variable first?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

echo date('l dS of F Y h:i:s A', $row_userLIST['date_created']);
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

date('l dS of F Y h:i:s A', $row_userLIST['date_created']);
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Superb...

Post by AliasBDI »

Now my dates and times are way off - up in the future - when they should be today. Is there a way to check my server time to see if it is off? Or is this a problem with my code saying the date wrong?

It reads: Monday 18th of January 2038 09:14:07 PM
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

What does echo $row_userLIST['date_created']; output?
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

this

Post by AliasBDI »

20040825192940

It is a TIMESTAMP column. I'm also doing this to a DATETIME column.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

That's not a Unix Timestamp, and that's what date requires. In your query use SELECT UNIX_TIMESTAMP(date_created) ... to get a unix timestamp.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

u need a unix time-stamp for that, generally its easier to use the mysql side of things for it

edit - why i even bother when a shooter like mark is around =]
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post by AliasBDI »

Didn't do a darn thing. Here is my query:

Code: Select all

SELECT UNIX_TIMESTAMP(date_created), id, username, domain, email, level, date_created, date_lastlogin, active FROM user_info
Does it matter that I'm on a Windows 2000 server?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

SELECT *, UNIX_TIMESTAMP(date_created) date_created FROM user_info
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post by AliasBDI »

Super. Pure genious are you guys. Thanks for the help!
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post by AliasBDI »

Moderator....problem solved!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If the timestamp came from a query, the laziest soluition would have been:

SELECT DATE_FORMAT(timestamp, '%Y-%m%d %h:%i:%s') AS timestamp FROM table;
Post Reply