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

swapna's avatar

Week Number

i have this one 01 Jan 2018 to 07 Jan 2018 using this i want to get week number and start and end dates.

0 likes
9 replies
realrandyallen's avatar
Level 44

Try this out:

$date = Carbon::parse("01 Jan 2018");

$weekNumber = $date->weekNumberInMonth;
$start = $date->startOfWeek()->toDateString();
$end = $date->endOfWeek()->toDateString();

dump($weekNumber);
dump($start);
dump($end);
swapna's avatar

01 Jan 2018 to 07 Jan 2018 there is to not only 01 Jan 2018

swapna's avatar

yup used but how to find week number

realrandyallen's avatar

@SWAPNA - You'll get the same exact result because Jan 7th is still the first week and the start and end of the week is the same as Jan 1st

However @Insperio is right that you may need to use weekOfYear depending on your needs

swapna's avatar

any one is here?

i have jan,2020 i want start date and end date of this month

nycofox's avatar

@SWAPNA - Carbon has the functions startOfMonth() and endOfMonth() that will return the dates you want.

Please or to participate in this conversation.