Page 1 of 1
Date calculation format
Posted: Thu Jan 04, 2007 3:39 pm
by evolozik
hey guys
i need to calculate the time left, here is my code
Code: Select all
$end=$new['ending_date'];
$current=date('Y-m-d His');
$timeleft=$end-$current;
the $end is in the same format as $current
why don't i have a correct answer in the same format for $timeleft
Posted: Thu Jan 04, 2007 3:42 pm
by Kieran Huggins
what it looks like you'll get is the number of seconds left - is that what you want?
Posted: Thu Jan 04, 2007 3:43 pm
by evolozik
in fact i want the time left to be in the form
day-hour-mins-seconds
Posted: Thu Jan 04, 2007 3:44 pm
by Kieran Huggins
well.. convert it!
60 seconds in a minute, 60 minutes in an hour....
Posted: Thu Jan 04, 2007 3:53 pm
by evolozik
i can't use maths because
gives me zero
does php allow this kind of calculation?
till now in tutorials i saw calculation either with time being initialised by code and not from database or directly from 2 colums in the database
Posted: Thu Jan 04, 2007 4:02 pm
by Kieran Huggins
I thought you were using time() for a second... you'll need to use strtotime() on each variable to get the unix timestamp, then subtract those:
Code: Select all
$timeleft=strtotime($end)-strtotime($current);
Posted: Thu Jan 04, 2007 11:03 pm
by evolozik
Thx Kieran Huggins, was able to solve it
