...

View Full Version : How to get the startdate and enddate of the week



che_anj
11-26-2007, 01:13 PM
Anyone knows how to get the start date and end date of the week..

example theres (2007-11-19)- (2007-11-23) or Monday-Friday..


thanks

Fumigator
11-26-2007, 04:42 PM
The "w" parameter of the date() function gives you day-of-week. So begin a loop with today's date and then advance from that date forward (or backward) calling date() with the "w" parameter until you reach the desired value.

che_anj
11-27-2007, 08:28 AM
Ive got this code that gets the start date of the week.. Anyone has idea how to get the enddate of the week..




function working_days (){
$date = date('Y-m-d');
$year = substr($date, 0,4);
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);

$d_daysinmonth = date('t', mktime(0,0,0,$month,1,$year)); // how many days in month
$full_weeks = ceil ($d_daysinmonth / 7);
$festive_days = floor(($d_daysinmonth / 7) * 2);
$total_working_days = $d_daysinmonth - $festive_days;
$total_working_hours = $total_working_days * 8;
return $total_working_days;
}
echo $total_working_days=working_days();
function working_weeks_combo () {

$date = date('Y-m-d');
$year = substr($date, 0,4);
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);

$d_daysinmonth = date('t', mktime(0,0,0,$month,1,$year)); // how many days in month
$full_weeks = ceil ($d_daysinmonth / 7);
$d_firstdow = date('w', mktime(0,0,0,$month,'1',$year)); // FIRST falls on what day of week (0-6)
$ajuste = $d_firstdow -1;
$new_date = date('Y-m-d', strtotime("$year-$month-01 - $ajuste days"));

echo '<select name="working_week">';
for ($ax=0; $ax < $full_weeks; $ax++){
echo "<option>".date('d/m/Y', strtotime($new_date. "+ $ax week"));
}
echo "</select>";
}

Inigoesdr
11-27-2007, 07:54 PM
$enddate = $startdate + 7;

aedrin
11-27-2007, 08:16 PM
I think he's asking for a function that gives the start date (monday) and end date (friday) for a given week number.

che_anj
11-28-2007, 03:17 AM
yeah, could u give me a function that gets the end date of the current week.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum