Reputation: 786
For example, today is Thursday, is there a date()
or strtotime()
usage that allows me to know last Thursday date?
When executed today (01-22-2015) it should return 01-15-2015
And if I execute that script tomorrow it should return the last week's friday, 01-16-2015
Upvotes: 0
Views: 85
Reputation: 1315
You can try this:
<?php
echo date("Y-m-d", strtotime('-1 week'))."\n";
You can look at other examples with strtotime()
at php.net
If you want, you can also use DateTime class for this purpose:
<?php
$date = new DateTime('now');
$date->sub(new DateInterval('P1W'));
echo $date->format('Y-m-d')."\n";
In this example 'P1W'
means 1 week period
. About DateInterval
format you can read here.
Upvotes: 3
Reputation: 474
Below is the code
<?php
echo date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-7, date("Y")));
?>
Upvotes: 1