Jump to content

Archived

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

onlyican

The monday for the week holding 27 july

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

Share this post


Link to post
Share on other sites
Are you looking for the day before Monday or the following Sunday?  You can just use a similar strtotime with ("-1 day", $from_date) or +7 day

Share this post


Link to post
Share on other sites
This will work:
[code]$check_date="2006-09-23";
$check_date = strtotime($check_date);

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

Ronald   8)

Share this post


Link to post
Share on other sites
so all I had to do was change the "last monday" to "this monday";

ok
Thankx

Share this post


Link to post
Share on other sites
my little example lol.

[code]
<?php
$today=date("l");
echo "today is $today<br>";

$convert=strtotime($today)+259200;

$result=date(l,$convert);

echo "But i want $result";

?>
[/code]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.