Page 1 of 1

PHP DATE: Five minutes ago?

Posted: Thu Jan 08, 2009 2:08 pm
by JAB Creations
Well here is the date/time, though what would be a good way of getting the time exactly five minutes ago?

Code: Select all

<?php
$date_current = date('o-m-d H:i:s');
echo $date_current;
echo '<div>-5 minutes</div>';
?>

Re: PHP DATE: Five minutes ago?

Posted: Thu Jan 08, 2009 2:24 pm
by Eran

Code: Select all

$date_past = date('o-m-d H:i:s',time() - 5 * 60);

Re: PHP DATE: Five minutes ago?

Posted: Thu Jan 08, 2009 2:26 pm
by JAB Creations
That is freaking awesome, thanks! :mrgreen:

Re: PHP DATE: Five minutes ago?

Posted: Thu Jan 08, 2009 3:25 pm
by VladSun

Code: Select all

echo date('H:i:s', strtotime('5 minutes ago'));
:mrgreen:

Re: PHP DATE: Five minutes ago?

Posted: Thu Jan 08, 2009 4:31 pm
by JAB Creations
VladSun, that's cool though I presume it takes additional resources to convert it to something along the lines of what pytrin posted?

Re: PHP DATE: Five minutes ago?

Posted: Thu Jan 08, 2009 4:38 pm
by VladSun
JAB Creations wrote:VladSun, that's cool though I presume it takes additional resources to convert it to something along the lines of what pytrin posted?
That's obvious ;)
But ... next time you ask how to get e.g. "the second tuesday of a given month and year" I'll use strtotime again:

Code: Select all

date("Y-m-d", strtotime("second tuesday", mktime(0, 0, 0, $month, 0, $year)));