Michael St Clair
Michael St Clair

Reputation: 6615

Use mktime on Date based on first day of month

Is there a way that I can have mktime go back a certain amount of months based of the first day of the month rather than the current day? Right now my code is echoing March instead of February because there is no 29 in February.

date("F Y", mktime(0, 0, 0, date('m') - 8, date('d'), date('Y')))

Upvotes: 1

Views: 235

Answers (1)

omma2289
omma2289

Reputation: 54619

Just set the "day" parameter to 1:

date("F Y", mktime(0, 0, 0, date('m') - 8, 1, date('Y')))

Upvotes: 3

Related Questions