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
evolozik
Forum Newbie
Posts: 14 Joined: Thu Jan 04, 2007 1:20 pm
Post
by evolozik » Thu Jan 04, 2007 3:39 pm
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
Last edited by
evolozik on Thu Jan 04, 2007 3:42 pm, edited 1 time in total.
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Thu Jan 04, 2007 3:42 pm
what it looks like you'll get is the number of seconds left - is that what you want?
evolozik
Forum Newbie
Posts: 14 Joined: Thu Jan 04, 2007 1:20 pm
Post
by evolozik » Thu Jan 04, 2007 3:43 pm
in fact i want the time left to be in the form
day-hour-mins-seconds
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Thu Jan 04, 2007 3:44 pm
well.. convert it!
60 seconds in a minute, 60 minutes in an hour....
evolozik
Forum Newbie
Posts: 14 Joined: Thu Jan 04, 2007 1:20 pm
Post
by evolozik » Thu Jan 04, 2007 3:53 pm
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
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Thu Jan 04, 2007 4:02 pm
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);
evolozik
Forum Newbie
Posts: 14 Joined: Thu Jan 04, 2007 1:20 pm
Post
by evolozik » Thu Jan 04, 2007 11:03 pm
Thx Kieran Huggins, was able to solve it