-1

I have an issue with the php date function when getting the week it is incrementing it by 1.

For example:

2020-11-31 is becoming week 49 instead of week 48.

Code as follows:

date("W",strtotime("2020-11-30"));

1 Answers1

3

First of all November has 30 days, not 31. 2nd, if you pass the correct date 2020-11-30 then this IS 49th week indeed. Week Number:49/2020 Start Date: Nov 29, 2020 End Date: Dec 5, 2020

You can also do this:

$ddate = "2020-11-30";
$date = new DateTime($ddate);
$week = $date->format("W");
echo "Week Number: $week";
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Sorry had a mistake i meant the 30th but as you can see 2020-11-30 falls under week 48 not 49 – Matthew Scicluna Dec 29 '20 at 15:44
  • 2
    Week 49 starts 30/11 and ends 6/12 in 2020 – RiggsFolly Dec 29 '20 at 15:49
  • How do you figure? https://whatweekisit.com shows it as week 49, as does https://www.epochconverter.com/weeks/2020 – aynber Dec 29 '20 at 15:49
  • From what I can see here: https://www.timeanddate.com/date/weeknumber.html and here https://www.calendar-365.com/week-number.html OR pull up your excel and type in the date in the column A2, then in another column do =WEEKNUM(A2), it will show you date week num as 49. Again PHP returns the correct week num. – Bojan Antonijevic Dec 29 '20 at 15:54
  • @MatthewScicluna _as you can see_ ...see where, exactly? All the links provided show the opposite. Do you have an alternative source of information? Some alternative facts from alternative universe, perhaps? – ADyson Dec 29 '20 at 16:15