0

I have been trying to work out how to get the exact time to the second until a certain day and hour. I believe it is the time function in php but i cant seem to get my head around it.

I am trying to spit it out in the following format 'dd:hh:mm:ss'

Thanks

zx81
  • 41,100
  • 9
  • 89
  • 105
user393273
  • 1,430
  • 5
  • 25
  • 48
  • possible duplicate of [How many days until XXX date?](http://stackoverflow.com/questions/654363/how-many-days-until-xxx-date) – Yoshi Jul 29 '11 at 07:59
  • Take a look at this previous question that should help you along: [http://stackoverflow.com/questions/654363/how-many-days-until-xxx-date](http://stackoverflow.com/questions/654363/how-many-days-until-xxx-date) – simnom Jul 29 '11 at 07:58

2 Answers2

1

You can use datediff for that http://www.php.net/manual/en/datetime.diff.php, and the following is how you use date to format it the way you want

http://php.net/date echo date("d:H:i:s");

EDIT:

if your php version doesn't permit, you could use:

function datediff($date) {
    return strtotime($date) - time();
}

echo datediff("2011-12-31 15:00");
Andreas Wong
  • 59,630
  • 19
  • 106
  • 123
  • Agree this is probably the best method but the only restriction being the PHP version installed. – simnom Jul 29 '11 at 08:00
0
echo date('d:H:i:s', mktime($hour, $minute, $second, $month, $day, $year));

Where mktime() returns a timestamp.

Vili
  • 1,599
  • 15
  • 40