Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Date and Time from MySQL
Old 08-14-2004, 11:19 AM Date and Time from MySQL
Unknown.

Posts: 1,693
Trades: 0
Just a simple question..I cant work out

If I have a field in MySQL set as DATETIME so its set out like..
0000-00-00 00:00:00

When I query this in php how can I get this to be displayed like...

14-08-2004 15:10 ??

And also how can I order the results by date.. so the newest are shown first and vice-versa??

Thanks

-James

Last edited by Dark-Skys99; 08-14-2004 at 11:23 AM..
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-14-2004, 12:51 PM
Average Talker

Posts: 16
Trades: 0
PHP Code:
$time strtotime($mysqlRow['dateTime']);
$date date("m-d-Y H:i"$time);
echo 
$date
that should work...

"SELECT * FROM yourTable ORDER BY yourDateTimeField DESC"
or
"SELECT * FROM yourTable ORDER BY yourDateTimeField (ASC)"

if you want to display your date/time different go to php.net and search for the date function...

hope this works for you..
__________________
-=nestyra.com=-

Last edited by nestyra; 08-14-2004 at 12:55 PM..
nestyra is offline
Reply With Quote
View Public Profile
 
Old 08-14-2004, 03:03 PM
Unknown.

Posts: 1,693
Trades: 0
Thanks

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 08-14-2004, 05:00 PM
Unknown.

Posts: 1,693
Trades: 0
Some other things to do with the date and time...

Basically I want to set it up so that it will display if a user is online or offline..

Say i have a field called 'activetime' which is updated everytime a user loads a page...

And Ive already selected all the stuff from the database and 'activetime' is refered to as $activetime

What would the code for the PHP be so that...

If $activetime is older than 5mins then do this....
otherwise do this....

??

Also what would the php be so it selects all the rows from the database where the 'activetime' field is no older than 5mins???

Thanks in advance

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 08-14-2004, 06:35 PM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
PHP Code:
$active_time time() - (60*5); // 60*5 = 5 mins in seconds :p
if(strtotime($your_variable['timedatestamp'])>=$active_time) { /* Active */ }
else { 
/* Not active */ 
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
Reply With Quote
View Public Profile Visit webwoRRks's homepage!
 
Old 08-14-2004, 06:38 PM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
OK, as for this;

Quote:
Also what would the php be so it selects all the rows from the database where the 'activetime' field is no older than 5mins???
Personally, where I'm working with a timestamp, I use a int of length 20 (Just in case my website lasts that long!), that way its easy to handle;

SELECT * FROM userinf WHERE last_thing>=$active_time
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
Reply With Quote
View Public Profile Visit webwoRRks's homepage!
 
Old 08-14-2004, 08:26 PM
Unknown.

Posts: 1,693
Trades: 0
Thanks

Just one more thing I've thought of...

Would it be possible that if $activetime is today it will display..
Today at 00:23

and if its yesterday...

Yesterday at 00:23

Otherwise just display the date...

13-08-2004 at 00:23

Thanks

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Date and Time from MySQL
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27429 seconds with 12 queries