Hi,
I have a little calendar application that I'm building and I have built in a nice little javascript forward and back button. I am able to calculate the week without a problem, but am having difficulty in changing the weekly data for that week.
My thinking is that if I can calculate the dates that are within that week, that might be the ticket. I'm not sure if that's the best way to go about it - but if anyone can provide insight on either:
1) the way to determine which dates are within a given week number in a particular year
or
2) a better way to calculate the dates moving forward or backward a week
it would be very much appreciated!!!
Thanks!
How to calculate starting date in week where week is known
Moderator: General Moderators
-
dardsemail
- Forum Contributor
- Posts: 136
- Joined: Thu Jun 03, 2004 9:02 pm
-
dardsemail
- Forum Contributor
- Posts: 136
- Joined: Thu Jun 03, 2004 9:02 pm
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you've already got the timestamp to get the week number, why waste time getting the timestamp again? You can use date() and strtotime() to find the start of the week (varies by country) like this (untested)
Code: Select all
$start_time = strtotime( ($days_diff = (date('w', $time) - $start_of_week)) ? (($days_diff > 0) ? '+' : '') . $days_diff . ' days ' : '') . '00:00:00' );
$end_time = $start_time + 8 * 24 * 60 * 60 - 1;-
dardsemail
- Forum Contributor
- Posts: 136
- Joined: Thu Jun 03, 2004 9:02 pm
I'm totally baffled by that last posting... sorry!
I've been trying with this to no avail:
week is a number passed from the URL.
The week # is coming through fine... and the $selWeek value seems to be changing, but the date that appears is always today's date.
I want to try and have it pick the date based on the week value. Is that possible?
I've been trying with this to no avail:
week is a number passed from the URL.
Code: Select all
$week=$_GETї'week'];
echo $week." ";
$selWeek = strtotime($week);
echo $selWeek;
$selWeek = date("m.d.y",$selWeek);
echo $selWeek;I want to try and have it pick the date based on the week value. Is that possible?
-
dardsemail
- Forum Contributor
- Posts: 136
- Joined: Thu Jun 03, 2004 9:02 pm