Practical Web Programming

Saturday, October 31, 2009

PHP: How to Get the Week Day Dates

In PHP, Getting THE week day dates is not really that difficult. Using a combination of pre-defined PHP functions, you can achieve this. Here's how.

In this example function, I'll use Sunday as the start of the week. The function will accept the year, month and day - the day should be a Sunday, Ex: 2009, 10 and 25.


//FUNCTION TO GET THE WEEK DAY DATES
function get_week_day_dates($year, $month, $day)
{
$start_of_week = mktime(0, 0, 0, $month, $day+(0-(int)date('w')), $year);
for ($x=0; $x<7; $x++)
{
print date('Y-m-d', $start_of_week + $x * 60 * 60 * 24) ."<br/>";
}
}

//USING THE FUNCTION
get_week_day_dates(2009, 10, 25);

1 comments:

Anonymous said...

Joel - I would like to speak with you about a PHP development opportunity in Atlanta, but I don't know how to contact you. Please email me as soon as possible to discuss the opportunity. Thanks!

-Shaun
SSorrells@BeaconHillStaffing.com

Recent Post