PHP DATE: Five minutes ago?

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

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

PHP DATE: Five minutes ago?

Post 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>';
?>
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP DATE: Five minutes ago?

Post by Eran »

Code: Select all

$date_past = date('o-m-d H:i:s',time() - 5 * 60);
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: PHP DATE: Five minutes ago?

Post by JAB Creations »

That is freaking awesome, thanks! :mrgreen:
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP DATE: Five minutes ago?

Post by VladSun »

Code: Select all

echo date('H:i:s', strtotime('5 minutes ago'));
:mrgreen:
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: PHP DATE: Five minutes ago?

Post 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?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP DATE: Five minutes ago?

Post 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)));
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply