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
https://forums.phpfreaks.com/topic/21679-the-monday-for-the-week-holding-27-july/
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.