Get the First day of the Week with an Exact Date
This is a small snippet of code I used on a calendar application I've been building. This small snippet gets the first day of the week if you have an exact date in mind.
function get_week_start($year, $month, $day)
{
$timestamp = mktime(0, 0, 0, $month, $day, $year);
return $timestamp = mktime(0, 0, 0, $month, date('d', $timestamp)-date('w', $timestamp), $year);
}
While that code gets the first day of the week, the next one gets the laste day of the week.
function get_week_end($year, $month, $day)
{
return get_week_start($year, $month, $day) + 518400;
}
Hope that helps.
By the way, this code was also posted on DevHow
Categories: How To
Tags: php
No Comments