Andrei Cristian Prodan
Andrei Cristian Prodan

Reputation: 1122

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 e.g. 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.

Upvotes: 0

Views: 49

Answers (2)

Aleks G
Aleks G

Reputation: 57316

Use the combination of strtotime and date functions:

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

Upvotes: 2

KernelM
KernelM

Reputation: 8916

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.

Upvotes: 1

Related Questions