How get one week date using PHP

This is a short guide on how to get the date of the week from a monday to sunday in PHP. This is useful for whenever you need to figure out what date a particular date fell on (or will fall on in the future). In this tutorial, I will be retrieving the date from a YYYY-MM-DD string.

Example

$data ['monday']    = date( 'Y-m-d', strtotime('monday this week'));
$data ['tuesday']   = date( 'Y-m-d', strtotime('tuesday this week'));
$data ['wednesday'] = date( 'Y-m-d', strtotime('wednesday this week'));
$data ['thursday']  = date( 'Y-m-d', strtotime('thursday this week'));
$data ['friday']    = date( 'Y-m-d', strtotime('friday this week'));
$data ['saturday']  = date( 'Y-m-d', strtotime('saturday this week'));
$data ['sunday']    = date( 'Y-m-d', strtotime('sunday this week'));

Leave a Reply

Your email address will not be published. Required fields are marked *