Current location: Hot Scripts Forums » Programming Languages » PHP » Compare timestamps


Compare timestamps

Reply
  #1 (permalink)  
Old 10-12-05, 04:02 PM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
Compare timestamps

Hi

Iam trying to get two timestamps to compare

One is created when the page is loaded, the other is stored ina db.

I want to find the difference in seconds between to two...

I try subtraction, but that is not valid as it doesnt work in 60's for seconds or hours. etc...

Any tips or howto's ?
Reply With Quote
  #2 (permalink)  
Old 10-12-05, 04:29 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
I can't quit get that!
normal substration will give the difference in seconds.
then you should devide by 60 to get it by mintues.
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 10-12-05, 05:14 PM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
okay

If I have this

PHP Code:



 $now 
"220505";
 
$time "230505";

 
$total $time $now "60" "60" "60";

 echo 
$total
shouldnt that return the seconds between the two times ?

Last edited by perleo; 10-12-05 at 05:46 PM.
Reply With Quote
  #4 (permalink)  
Old 10-12-05, 05:40 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Is the code in your post literally what you are using? If so, take a 2nd look at the echo. It has time in it, not total. ---

echo $time;
Reply With Quote
  #5 (permalink)  
Old 10-12-05, 05:46 PM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
sorry, should be $total; i get this as the output

230838.93037
Reply With Quote
  #6 (permalink)  
Old 10-12-05, 05:56 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Actually do this -

PHP Code:

$total = ($time $now) / 60 60 60
The division was being performed 1st on $now then the subtraction is performed...

Last edited by mab; 10-12-05 at 05:59 PM.
Reply With Quote
  #7 (permalink)  
Old 10-13-05, 09:47 AM
Satria Satria is offline
Newbie Coder
 
Join Date: Sep 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
what ever your time format... make it to Unix.Timestamp first
either using SQL or using mktime() function
and format back to your format using strftime()
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare arrays drophit PHP 0 07-09-05 03:33 PM
Compare Two Databases Reliant84 Windows .NET Programming 4 07-13-04 10:46 AM
compare the contents of 2 file in php rani PHP 5 04-14-04 11:47 PM
compare number values in mysql? 7crystal7 PHP 1 03-13-04 04:41 AM
Difference between timestamps? Cagez PHP 1 08-09-03 08:59 PM


All times are GMT -5. The time now is 06:16 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.