Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dpelto's avatar

Get first day of month from a given date

In Microsoft Access I can do this:

MyDate = !TransactionDate
MyNewDate = DateSerial(Year(MyDate), Month(MyDate), 1)

For example if MyDate is 02/25/2020, MyNewDate would be 02/01/2020

How would you do that using php? Thanks

0 likes
4 replies
Nakov's avatar

In Laravel there is a library used to do this called Carbon, so just as simple as this:

Carbon\Carbon::parse('02/25/2020')->startOfMonth()->format('m/d/Y')
dpelto's avatar

@nakov thank you, but what would it be in plain php, no carbon.

Nakov's avatar
Nakov
Best Answer
Level 73

@dpelto here:

echo date('m/01/Y', strtotime('02/25/2020'));

Please or to participate in this conversation.