This article mainly introduces PHP to calculate the start date and end date of the week of the given date, involving PHP date and time-related operations and conversion skills, with a certain reference value, the need for friends can refer to the next
This example describes the start and end dates of the week in which PHP calculates the given date. Share to everyone for your reference, as follows:
<?php/** * Gets the start date and end date of the week of the given date * @param string $gdate date, default to day, format: YYYY-MM-DD * @param int $weekStart Week with Monday or Sunday, 0 for week Days, 1 for Monday * @return array Array ("Start date", "End Date"), */function getaweektimeslot ($gdate = ", $weekStart = 0) {if (! $g Date) {$gdate = date ("y-m-d"), $w = Date ("W", Strtotime ($gdate)); Get the day of the week, starting in Sunday 0-6 $dn = $w? $w-$weekStart: 6; The number of days to subtract $st = Date ("y-m-d", Strtotime ("$gdate -". $dn. "Days ")); $en = Date ("y-m-d", Strtotime ("$st +6 days "); Return Array ($st, $en); Returns the start and end dates} $timeSlot =getaweektimeslot (' 2017-01-24 ', 1); echo "Week start:{$timeSlot [0]}--->week end: {$timeSlot [ 1]} ";? >
The results of the operation are as follows:
Week start:2017-01-23--->week end:2017-01-29
The above is the whole content of this article, I hope that everyone's study has helped.