简体   繁体   中英

Get first week date of the month providing day?

Is there any PHP function that returns the date of the first week ,

i:e, if i pass "Monday" , it should return 02 of september,
i know, how to get the day, month, date like

date('l') , date('m'), date ('d') 

But stuck at this point

This should get you started:

$dt = new DateTime('first Monday of this month');
echo $dt->format('l m d');

See it in action

You can use strotime() , like so:

function getDateFromDay($day) {
    return date('d-m-Y', strtotime("first $day of this month"));
}

Usage:

echo getDateFromDay('Monday');

Output:

02-09-2013

Demo!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM