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
PHP date time, Get only within last 2 minutes..
Old 06-25-2010, 11:32 AM PHP date time, Get only within last 2 minutes..
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi Guys,
My knowledge of the PHP date function is useless i just cant get to grips with it..
So if anyone can help with an example or a working way that would be great..

I have a script that has a date stamp like $datetime = "Jun 25 15:40:54"


How can i check this against the system time and only do stuff if its in the last 2 minutes?

Ie:

if ($datetime "is in the last 2 minutes") {
do stuff;
}

Info: Its a linux server if that helps.



Any help here would be great.

Thanks
G
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 06-25-2010, 11:43 AM Re: PHP date time, Get only within last 2 minutes..
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
personally, either use a seperate variable for this purpose (eithe just the min and sec values or a unix timestamp.

Alternativley,

explode() the :'s and use the last two parts of the array, i.e. the min and sec portions.
__________________

Please login or register to view this content. Registration is FREE

Learn professional skills from professional people, from $6.50 a month.
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 06-25-2010, 11:55 AM Re: PHP date time, Get only within last 2 minutes..
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Someone has come up with the idea of:

<?php
$datetime
= "Jun 25 15:40:54";
$now = time();
$now_minus2 = $now - 120;
$now_plus2 = $now + 120;
$comp = strtotime($datetime);
if (
$comp >= $now_minus2 && $comp <= $now_plus2) {
echo
"$datetime is within range<br>\n";
} else {
echo
"not within range<br>\n";
}
?>


It seems to work, Maybe someone here knows how to make this cleaner?


Thanks
G
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 06-25-2010, 03:27 PM Re: PHP date time, Get only within last 2 minutes..
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Do you have a db at hand?
They excel at that work. You could just send a query that returns 1 or 0 if the difference between now() and a date is less than 2 minutes
PHP Code:
<?php
$datetime 
"Jun 25 15:40:54";
$tstamp strtotime($datetime);
$fullDate=strftime('%Y-%m-%d %H:%M:%S',$comp);  //output "2010-06-25 15:40:54"
$query="select passed=case when TIMESTAMPDIFF(minute, '$fullDate', now())<=2 then 0 else 1 end;"
$res=mysql_query($query);
while(
$o=mysql_fetch_object($res)){
    if(
$o->passed==1){
        
//2 minutes have passed
    
}
}
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 06-25-2010 at 04:41 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 06-25-2010, 03:53 PM Re: PHP date time, Get only within last 2 minutes..
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
I do

Thanks for the re-worked version. At least i have 2 options now

Thanks again.

-G
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 06-26-2010, 12:30 AM Re: PHP date time, Get only within last 2 minutes..
Novice Talker

Posts: 12
Name: Amber Hunter
Location: Fort Worth, TX
Trades: 0
Quote:
Originally Posted by lynxus View Post
Someone has come up with the idea of:
It seems to work, Maybe someone here knows how to make this cleaner?
That's really close to a script I put together that was supposed to show recently registered users. Ugly maybe, but if its any consolation it seems to work pretty well.
__________________

Please login or register to view this content. Registration is FREE

1706 N. Stemmons Frwy. (I-35E)
Lewisville, TX 75067
amber0hunter is offline
Reply With Quote
View Public Profile Visit amber0hunter's homepage!
 
Reply     « Reply to PHP date time, Get only within last 2 minutes..
 

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.24527 seconds with 12 queries