In PHP, I'm generating a calendar with code from here. I've connected it with Basecamp and am successfully calculating the hours worked each day and sum them for the week and month. To properly calculate overtime, I need the hours from the whole week, even when it spans the end/beginning of a month.
After several hours of trying, I haven't been able to calculate the dates of the days marked with '?' in the above image.
I can't escape the feeling that I'm missing something obvious here, but haven't been able to figure it out. Any help much appreciated, thank you.
You can use
mktime() and set a day argument which is less than
0 for the last day,
-1 for the day before the last day, etc.
That gives you a UNIX timestamp you can use to find out the weekday and then - until you've reached Sunday/Monday (whatever week start you use) - subtract -86400 or call
mktime() again with the day reduced by 1.
mktime(0, 0, 0, 12, -1, 2010); # timestamp of Nov 29th 00:00:00 2010
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki