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

deladels's avatar

Creating date using day of week.

I've been trying to find a way to create dates using the day of the week (i.e Monday in words or 1 as an integer). Unfortunately, I can't seem to find anything online to get started with. Does anybody knows of any resource or have to implement anything of the sort?

All I'm aware of is creating a date by passing the year, month, and day (which I thought was Monday or the actual day, turns out it's the actual date).

Carbon::create(Carbon::now()->addWeek()->format('Y'), Carbon::now()->addWeek()->format('m'), 3)->toDateString();

// The 3 there I thought will be the day which in this case will be  Wednesday or so
0 likes
4 replies
Sinnbeck's avatar

So start from Monday and add days?

Simple example (you might need to subtract 1 from offset)

now()->startOfWeek()->addDays($offset);
Snapey's avatar
Snapey
Best Answer
Level 122

perhaps you could use like

now()->modify('next monday');    // 2022-03-28

Please or to participate in this conversation.