tags:

views:

134

answers:

6

Hi, I want a First Day Of a week say I have 45th week. Now I want to have date of the first sunday of this week. Can any one suggest me how I can go about this ?

Thank you

+1  A: 

you should strtotime and date function

some code like that

$next_sunday = strtotime('next sunday');
$next_week = strtotime('+1 week');
$next_sunday_of_next_week = strtotime('next sunday', $next_week);

hope this helps

RageZ
A: 

If you have the month, day and year:

$timestamp = mktime(0, 0, 0, $month, $day, $year);
 echo date('c', $timestamp) = mktime(0, 0, 0, $month, date('d', $timestamp)-date('w', $timestamp), $year);

you could also do it this way if you have the timestamp:

echo $date('c', mktime(0, 0, 0, $month, date('d', $timestamp)-date('w', $timestamp), $year));

From: http://pinoytech.org/blog/post/get-the-first-day-of-the-week-with-an-exact-date

Thorpe Obazee
A: 

date($str_format, strtotime($year."W".$week."1"))

Where $str_format is the output formate according to the PHP date() function.. I use 'M d Y'

Steven Xu
that works if you have Mondays as the first week.
Thorpe Obazee
A: 

See this to get some idea.

NawaMan
A: 

We can only help you if you can provide us some more details, in which language you want to achieve this, Clearly specify this needs to be done in any laguage, script or on database?

Sachin Chourasiya
Question is tagged with php.
notJim
A: 

Searching around a bit, the most suggested is:

$year = "2009"; // date("Y"); $week = "45"; // date("W");

$firstDayOfWeek = strtotime($year."W".str_pad($week,2,"0",STR_PAD_LEFT));

print("The first day of week ".$week." of ".$year." is ".date("D, d-m-Y",$firstDayOfWeek));

Basicly this comes down to letting strtotime do the work for you. You fill in "2009W45" and it'll retreive the date for you. Pitfall here is that the week needs to be in a 2 digit format. So week 1 needs to be 01, hence the str_pad to zero-fill it.

nash