简体   繁体   中英

How do you get the name of the day that is the first day of the certain Month/Year in php?

I need to create a function that takes month and year as parameters and returns the name of the day which was the 1st of the month.

For eg today is the 30th day of March 2012, how do I find out which day was the 1st? All I know is March 2012. Sorry for repeating, I just want to be clear.

Use the combination of strtotime and date functions:

$f_dt = strtotime("$month/01/$year");
$day = date('D', $f_dt);

Ack, totally misread... ok, instead that should be date('D',strtotime($year.'-'.$month.'-01'))

I assume by name of day you mean Monday, Tuesday, etc. Change the 'D' parameter there to 'l' (lowercase L) if you want the date written out instead of Mon, Tue, etc.

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