Syntax:
strtotime ($EnglishDateTime, $time_now)Parameters:The strtotime() function takes two parameter as above and described below:
- $EnglishDateTime:specifies a textual description of the date and time in English that represents the date or time to be returned. The function parses the string and returns the time in seconds. This parameter is required.
- $time_now:This parameter specifies the timelabel used to compute the return value. This is an optional parameter.
Syntax:
date (format, timestamp)Parameters:this function takes two parameters as specified above and described below:
- Format:Specify the date and time format in which the result will be displayed.
- Timestamp: is the default time variable from which the date will be generated.
// PHP pro gram for printing by default
// day of the current week
// I will show 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
;
?>
Exit:First day of this week: Monday - 02/04/2019
Sunday is generally considered the first day of the week. So, in PHP, to count Sunday as the first day of the week, consider the Sunday of the previous week. That is, to get the first day (Sunday) of the week, you need to get the Sunday of the previous week, and to get the first day (Sunday) of the next week, you need to get the Sunday of this week, and so on.
PHP supports -ve indexing in temporary string. Thus, to get the previous week, he might use the time string as "-1 week", and to get the day, he might also need to include the name of the day in the time string.Program 2: Get the first day (Sunday) of the week.
// PHP program to display Sunday as the first day of the week
// I will show the name of the day
// d, m and Y will show the day, month and year, respectively
// For the current week, the timeline will be & quot; Sunday -1 week & quot;
// here -1 stands for past 1st week
$firstday
=
date
(
’l - d / m / Y’
,
strtotime
(
"sunday -1 week"
));
echo
"First day of this week:"
,
$firstday
,
" "
;
// For the previous week, the timeline will be "Sunday -2 week" ;
// here -2 stands for the week before last week
$firstday
=
date
(
’ l - d / m / Y’
,
strtotime
( "sunday -2 week"
));
echo
"First day of last week:"
,
$firstday
,
" "
;
// During the next week, the timeline will be "Sunday 0 week" ;
// here 0 stands for this week
$firstday
=
date
(
’l - d / m / Y’
,
strtotime
(
"sunday 0 week"
));
echo
"First day of next week:"
,
$firstday
,
" "
;
// During the week following the next week, the timeline will be & quot; Sunday 1 week & quot;
// here 1 indicates the next week
$firstday
=
date
(
’l - d / m / Y’
,
strtotime
(
"sunday 1 week"
));
echo
"First day of week after next week:"
,
$firstday
;
?>
Exit:First day of this week: Sunday - 03/02/2019 First day of last week: Sunday - 27/01/2019 First day of next week: Sunday - 10/02/2019 First day of week after next week: Sunday - 17/02 / 2019