Jump to content

The monday for the week holding 27 july


onlyican

Recommended Posts

Hey guys

I am working on some code
and I want to get the date of Monday and the Date of Sunday for where the week is X

I did something like this

[code]
<?php

$check_date = isset($_POST["check_date"]) ? $_POST["check_date"] : date("Y-m-d");
echo $check_date;
$from_date = strtotime("this monday",$check_date);

$from_date = date("Y-m-d",$from_date);
echo "<br />\n";
echo $from_date;
?>
[/code]

The check date works (not using post, so current date would be today (2006-09-22)

The output is
2006-09-22
1970-01-05
now, the monday of this week is not 5 January 1970

So how would I work out the date for Monday and Sunday of a given date

Can anyone help me out here

Cheers

Link to comment
Share on other sites

ahh, well this is wha I got

[code]
<?php
function WeekDates($date){
$check_date_stamp = strtotime($date);

$week_day = date("w", $check_date_stamp);

$day = 60 * 60 * 24;

if($week_day == 1){
$check_date_stamp = $check_date_stamp + $day;

}
$from_date_stamp = strtotime("last monday",$check_date_stamp);


$from_date = date("Y-m-d",$from_date_stamp);

$last = $from_date_stamp + ($day * 6);


$to_date = date("Y-m-d", $last);

return array($from_date, $to_date);

}


$check_date = isset($_GET["date"]) ? $_GET["date"] : date("Y-m-d");



list($from_date, $to_date) = WeekDates($check_date);

?>
[/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.