strtotime() Function:
The strtotime() function returns the result in timestamp by parsing the time string.
Syntax:
strtotime($EnglishDateTime, $time_now)
Parameters: The strtotime() function accepts two parameters as mentioned above and described below:
date() Function: The date() function returns more understandable and human readable format of date.
Syntax:
date( format, timestamp )
Note: In PHP, the week starts with Monday, so if the time-string is given as “this week” the output will be timestamp of Monday which can make readable by passing it through date() function.
Program 1: Get the default first day of a week when the time-string is “this week”.
<?php
// PHP program to print default first
// day of current week
// l will display the name of the day
// d, m, Y will display the day, month
// and year respectively
$firstday = date('l - d/m/Y', strtotime("this week"));
echo "First day of this week: ", $firstday;
?>
<?php
// PHP program to display sunday as first day of a week
// l will display the name of the day
// d, m and Y will display the day, month and year respectively
// For current week the time-string will be "sunday -1 week"
// here -1 denotes last week
$firstday = date('l - d/m/Y', strtotime("sunday -1 week"));
echo "First day of this week: ", $firstday, "\n";
// For previous week the time-string wil be "sunday -2 week"
// here -2 denotes week before last week
$firstday = date('l - d/m/Y', strtotime("sunday -2 week"));
echo "First day of last week: ", $firstday, "\n";
// For next week the time-string wil be "sunday 0 week"
// here 0 denotes this week
$firstday = date('l - d/m/Y', strtotime("sunday 0 week"));
echo "First day of next week: ", $firstday, "\n";
// For week after next week the time-string wil be "sunday 1 week"
// here 1 denotes next week
$firstday = date('l - d/m/Y', strtotime("sunday 1 week"));
echo "First day of week after next week : ", $firstday;
?>