0
Good afternoon, I’m returning from the database the number of the week in the year.
["data_hora"]=>
string(16) "19/11/2018 15:26"
["num_semana"]=>
string(2) "47"
Where num_week is the number of the week of the year that the date 19/11/2018 this inserted. I need a way to take the first day of week 47 (Sunday) and the last day (Saturday). Does anyone have any idea how I can do this.
Something like
new DateTime('+46 weeks Sunday Jan 2018')
– Woss
More or less, but I need to pass the value of num_week, and it tells me when it starts and when it ends. Example num_week = 1
$inicio = 01/01/2018
$fim = 07/01/2018
– Guilherme Rigotti
Exactly. Just a matter of replacing the value.
– Woss
new DateTime('+46 weeks Sunday Jan 2018')
would not return me only the end date ?– Guilherme Rigotti
19 of 11 is in 47?
– user60252
@Leocaracciolo Yes the week 47 starts on the day 19/11 and goes up to 25/11
– Guilherme Rigotti
https://ideone.com/Rvg4pb
– user60252
@Leocaracciolo This return is the last day of the week 46 ?
– Guilherme Rigotti
incompatibility, in question Sunday is the first day and in comment the week begins on Monday
– user60252
take the first day of week 47 (Sunday) and the last day (Saturday). and in the commentary the week 47 starts on 19/11 and goes until 25/11 day 19 is Monday
– user60252
@Leocaracciolo Truth, I made this mistake at the time of the question, but anyway. I think this method that you went through will solve my problem.
– Guilherme Rigotti
Remembering that the definition of the first day of the week varies according to place, culture, religion, etc and depending can be Sunday, Monday or even Saturday: https://www.quora.com/What-is-the-first-day-of-the-week. If I’m not mistaken, in PHP
setISODate
uses the definition of ISO 8601, which uses Monday as the first day of the year, and to define the first week of the year, considers that it is the week that starts on a Monday and has at least 4 days in 2018: https://en.wikipedia.org/wiki/ISO_week_date#First_week– hkotsubo
http://sandbox.onlinephpfunctions.com/code/4dedf06de8252117df8837c4895864aae0a375e3
– user60252
In that case the last day would be https://ideone.com/t1Kk3y
– user60252