Convert week days to actual date

Hi, is it possible to convert “Tuesday” to actual date ? example the date of the day tuesday in this week is 2015-09-1

Thank you in advance.

http://php.net/manual/en/function.date.php

Or maybe I didn’t get your question?

2 Likes

I am confuse how to convert tuesday to exact date in this week to get
2015-09-01

use strtotime to get the appropriate week date, then convert that value to a date.

$date = new DateTime(strtotime('next Tuesday'));
echo $date->format('YY-mm-dd');
1 Like

Thank you for the reply, can I ask what is the ‘next’ ? I didn’t see that in manual.

It’s in the relative date formats: http://php.net/manual/en/datetime.formats.relative.php

it works now using this

echo date(‘Y-m-d’, strtotime(‘Tuesday’));

@DaveMaxwell, Thank you :smile:

You can also do it this way →

<?php

$myDate = new DateTime("Next Tuesday", new DateTimeZone("America/Detroit"));

echo $myDate->format("Y-m-d") . "<br>\n";
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.