Jump to content

Converting week number to start and end date of the week


smith.james0

Recommended Posts

Hi
I can get the start and end dates for a current week number by using mktime
[code]$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")));
[/code]

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
Link to comment
Share on other sites

try
[code]
<?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) ;

?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.