Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming > PHP Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-06-2009, 06:34 AM
  #1
Akkernight
Aspirant (Level 2)
 
Join Date: Apr 2009
Posts: 19
iTrader: (0)
Akkernight is an unknown quantity at this point
[SOLVED]Finding elapsed time between two times

Hello.

I'm having an issue with calculating the elapsed time between two times, and since my hoster doesn't provide PHP 3.0 yet, I can't make the premade functions, so I have to make my own.

Now, my PHP knowledge is new so I'm not used to functions and don't know many.

Code:
function time_diff($timeDeltaOne, $timeDeltaTwo){
	if($timeDeltaOne > $timeDeltaTwo){
		$time_latter = $timeDeltaOne;
		$time_earlier = $timeDeltaTwo;
	}
	else{
		$time_earlier = $timeDeltaOne;
		$time_latter = $timeDeltaTwo;
	}
	
	$diff = time_latter - time_earlier;
	
	return $diff;
		
}
This doesn't work, which is kinda obvious, I need integers but I don't know how to get some :S
So all help is appreciated and thanks in advance!

Last edited by Akkernight : 10-10-2009 at 02:14 PM.
Akkernight is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-06-2009, 07:19 PM
  #2
Horus_Kol
Mod of the Underlay
 
Horus_Kol's Avatar
 
Join Date: Jun 2002
Location: At a desk, hooked up and ready to rock
Posts: 17,242
iTrader: (0)
Horus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of light
Code:
$diff = $time_latter -  $time_earlier;
not at all sure why your function doesn't work (if the above is a typo) - what values are you sending to the function?

Can we see an example of use?
__________________
Personal Blog (and photos): HorusKol
Articles on Programming and Development (PHP/HTML/CSS, C/C++, more): RandomTweak

The great secret that no SEO agent wants you to hear: if you build your website using w3c accessibility guidelines and your content is written for people, you will do better for longer in search engines than any other method...

Last edited by Horus_Kol : 10-07-2009 at 09:52 PM.
Horus_Kol is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-07-2009, 09:32 AM
  #3
Akkernight
Aspirant (Level 2)
 
Join Date: Apr 2009
Posts: 19
iTrader: (0)
Akkernight is an unknown quantity at this point
oh whoops! I forgot the values, I was poundering over what code I was missing to post :S

Code:
$date = new DateTime();
$lastDate = new DateTime();
time_diff($date, $lateDate);
I hope this helps with the confusion
Akkernight is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-07-2009, 12:36 PM
  #4
¥åßßå
Blonde Bimbo
 
¥åßßå's Avatar
 
Join Date: Jul 2004
Posts: 2,244
iTrader: (0)
¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all
Quote:
Originally Posted by Akkernight View Post
and since my hoster doesn't provide PHP 3.0
Change hosts!

Quote:
Originally Posted by Horus_Kol View Post
Code:
$diff = $time_latter -  $time_earlier;
Assume you have the red bits in your code?

Quote:
Originally Posted by Akkernight View Post
Code:
$date = new DateTime();
$lastDate = new DateTime();
time_diff($date, $lateDate);
$lastDate && $lateDate?

Also, you don't do anything with the result of your function?

¥
__________________
I may have opened the door, but you entered of your own free will


Last edited by ¥åßßå : 10-07-2009 at 12:38 PM.
¥åßßå is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-07-2009, 01:00 PM
  #5
Akkernight
Aspirant (Level 2)
 
Join Date: Apr 2009
Posts: 19
iTrader: (0)
Akkernight is an unknown quantity at this point
Quote:
Originally Posted by ¥åßßå View Post
Change hosts!



Assume you have the red bits in your code?



$lastDate && $lateDate?

Also, you don't do anything with the result of your function?

¥
Well, I did echo the result and it turned to be 0 ... Also, I wrote some of the code directly into the reply box, so there I made some typos :S Anyways, your time is appreciated also maybe I forgot the '$' at the sub. part...
Also, I spent 1 hour talking to my host trying to get them to update, yet eventually I just got told that it won't come for some months! And I'll have to wait 'til my subscribion's off 'til I change host
Akkernight is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-07-2009, 01:47 PM
  #6
¥åßßå
Blonde Bimbo
 
¥åßßå's Avatar
 
Join Date: Jul 2004
Posts: 2,244
iTrader: (0)
¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all
The chances are that your (test) times have bugger all difference ( hence the "zero" ) .. you're setting both vars within nano-seconds of each other

¥
__________________
I may have opened the door, but you entered of your own free will

¥åßßå is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-07-2009, 04:43 PM
  #7
Akkernight
Aspirant (Level 2)
 
Join Date: Apr 2009
Posts: 19
iTrader: (0)
Akkernight is an unknown quantity at this point
ok, outputted the errors in a human readable manner...
http://aeresentertainment.com/three_...os_x=0&pos_y=0
top side of there the test results are, I've made tests that are several hours in between, still returns 0
Akkernight is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-09-2009, 08:05 AM
  #8
Akkernight
Aspirant (Level 2)
 
Join Date: Apr 2009
Posts: 19
iTrader: (0)
Akkernight is an unknown quantity at this point
*bump*

This is still an issue :S
Akkernight is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-09-2009, 05:48 PM
  #9
¥åßßå
Blonde Bimbo
 
¥åßßå's Avatar
 
Join Date: Jul 2004
Posts: 2,244
iTrader: (0)
¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all¥åßßå is a name known to all
Sorry, I've had a couple of busy days, so not even had time to think about my own problems, let alone yours .... *if* I get chance before I sod off on holiday ( for 14 days in malta ) then I'll post it here?

In the mean time, you may wish to change your date format into a timestamp

¥
__________________
I may have opened the door, but you entered of your own free will

¥åßßå is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-10-2009, 08:13 AM
  #10
Akkernight
Aspirant (Level 2)
 
Join Date: Apr 2009
Posts: 19
iTrader: (0)
Akkernight is an unknown quantity at this point
ok, fixed it
Here's the fix.

EDIT: Feel kinda stupid for not figuring this out >.<

Code:
function DateTime_diff($DateTime_DeltaOne, $DateTime_DeltaTwo, $format){

	if(strtotime($DateTime_DeltaOne->format($format)) > strtotime($DateTime_DeltaTwo->format($format))){
		$time_earlier = strtotime($DateTime_DeltaTwo->format($format));
		$time_latter = strtotime($DateTime_DeltaOne->format($format));
	}
	else{
		$time_earlier = strtotime($DateTime_DeltaOne->format($format));
		$time_latter = strtotime($DateTime_DeltaTwo->format($format));
	}
	
	
	
	$diff = $time_latter - $time_earlier;
	
	
	return $diff;
		
}
Code:
$diff = DateTime_diff($lastDate, $date, "Y-m-d H:i:s");
Akkernight is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


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



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 03:47 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.