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
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 .
Below is the code
<?php
echo date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-7, date("Y")));
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.