I am confused while using php to handle date/time.
What I am trying to do is this: When a user visits my page I am asking his timezone and then displaying the 'day of week' in his timezone.
I don't want to use the browser's day. I want to do this calculation in php.
This is how I am trying to achieve it:
- The timezone entered by user
- Unix time stamp calculated by php time() function.
But I dont know how to proceed... How would i get the 'day of week' in this timezone.
"Day of Week" is actually something you can get directly from the php date() function with the format "l" or "N" respectively. Have a look at the manual
edit: Sorry I didn't read the posts of Kalium properly, he already explained that. My bad.
Where $dw will be 0 (for Sunday) through 6 (for Saturday) as you can see here: http://www.php.net/manual/en/function.date.php
Check date is monday or sunday before get last monday or last sunday
I think this is the correct answer, just change
Europe/Stockholm
to the users time-zone.http://php.net/manual/en/function.date.php
For a list of supported time-zones, see http://php.net/manual/en/timezones.php