Time comparison issue

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

Post Reply
jaydrawmer
Forum Newbie
Posts: 2
Joined: Sun Apr 13, 2008 9:41 am

Time comparison issue

Post by jaydrawmer »

Hi All,

I've been searching around the internet for time/date comparisons, and to my 1st amazement, there was no built-in functionality... Secondly, there doesn't appear to be what I want to do.

I have 1 value which is the timestamp of when something began... I have another timestamp which is how long something takes, and I want to work out the finishing timestamp.

Either that or solve this problem...

I'm developing an online strategy game, and you will, for example, upgrade a building which might take 25 minutes. I'm also running alongside it, javascript which will show on teh screen how long something takes until it is complete. My initial thought was to run the same code in php as javascript, so the javascript is showing the user how long something will take, but only when the page is refreshed, the php will actually work it out and show you the next screen.

Hope this makes sense.

Regards,
Jason
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Time comparison issue

Post by Weirdan »

I have 1 value which is the timestamp of when something began... I have another timestamp which is how long something takes,
I guess the second value you have is duration in seconds, not a timestamp.
and I want to work out the finishing timestamp.
Just add a duration to the start timestamp:

Code: Select all

 
$start = time();
$duration = 30; // seconds
$end = $start + $duration;
 
Post Reply