Jump to content

Using unix time to determine a countdown


mforan

Recommended Posts

ok so lets say, in my database is set a time in unix, in the future. lets say + 2 days from now.

 

i want to display some output that would say:

 

2 days, 0 hours and 0 minutes remaining.

 

obviously this would grab the current time() and compare it to the value in the database....

but how do i go about even making something that can do this?

 

<?php
$newTime = time()+3600*24*2; // todays from now.
$timeLeft = $newTime - time();

echo date('d', $timeLeft) . " days left";
?>

 

That probably will not get you the exact results but it is a start.

 

You may want to look into strtotime also.

Yer both values are going to have to be inputted through as unix thou. Since its like a que timer, I want ny users to know how long they have left to wait.

 

I considered using java script here but it won't be nessasary reallly + its always better to use as little variations of coding type as possible.

 

I've checked up on the google for some infos about php count down but none seem to use unix other than time() feature which is an obvious requirement since u are comparing whatever value to this.

 

Is ther a way to convert time() to say something like Date(0,0,0,0,0) just with numbers?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.