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
AliasBDI
Forum Contributor
Posts: 286 Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA
Post
by AliasBDI » Wed Aug 25, 2004 8:28 pm
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.
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Wed Aug 25, 2004 8:33 pm
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
Post
by AliasBDI » Wed Aug 25, 2004 8:40 pm
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?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Wed Aug 25, 2004 8:43 pm
Code: Select all
echo date('l dS of F Y h:i:s A', $row_userLIST['date_created']);
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Wed Aug 25, 2004 8:43 pm
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
Post
by AliasBDI » Wed Aug 25, 2004 8:45 pm
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
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Wed Aug 25, 2004 8:48 pm
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
Post
by AliasBDI » Wed Aug 25, 2004 8:49 pm
20040825192940
It is a TIMESTAMP column. I'm also doing this to a DATETIME column.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Wed Aug 25, 2004 8:52 pm
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.
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Wed Aug 25, 2004 8:54 pm
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 » Wed Aug 25, 2004 9:03 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 25, 2004 9:18 pm
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 » Wed Aug 25, 2004 9:26 pm
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 » Mon Aug 30, 2004 2:13 pm
Moderator....problem solved!
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Mon Aug 30, 2004 4:36 pm
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;