# Converting week number to start and end date of the week

1 reply to this topic

### #1 smith.james0

smith.james0
• Members
• 122 posts

Posted 30 October 2006 - 08:24 PM

Hi
I can get the start and end dates for a current week number by using mktime
```\$StartOfWeek = date("d",mktime(0,0,0,date("n"),(date("j")-date("w")),date("Y")))."/".date("m",mktime(0,0,0,date("n"),(date("j")-date("w")),date("Y")))."/".date("Y",mktime(0,0,0,date("n"),(date("j")-date("w")),date("Y")));

\$EndOfWeek = date("d",mktime(23,59,59,date("n"),(date("j")+(6-date("w"))),date("Y")))."/".date("m",mktime(23,59,59,date("n"),(date("j")+(6-date("w"))),date("Y")))."/".date("Y",mktime(23,59,59,date("n"),(date("j")+(6-date("w"))),date("Y")));
```

The problem is a need to be able to find the start and end date of any week inputted via a form. I have had a good look round the web, but i have been unable to find anything to point me in the right direction. Can anyone help?

Thanks James

### #2 Barand

Barand
• Moderators
• Sen . ( ile || sei )
• 18,021 posts

Posted 30 October 2006 - 09:28 PM

try
```<?php
// assuming wk1 contains Jan 1st
\$wk = 44;
\$day1 = mktime (0,0,0,1,1,date('Y'));
\$days = (\$wk - 1) * 7;
\$d = strtotime ("+\$days days", \$day1);
\$dow = date('w', \$d);
\$sunday = strtotime ("-\$dow days", \$d);
\$saturday = strtotime ("+6 days", \$sunday);

echo date ('D jS F, Y', \$sunday). ' to ' . date ('D jS F, Y', \$saturday) ;

?>
```

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.