Jump to content


Photo

The monday for the week holding 27 july


  • Please log in to reply
5 replies to this topic

#1 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 22 September 2006 - 04:03 PM

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

<?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;
?>

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


Tell me the problem, I will try tell you the solution

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 22 September 2006 - 04:12 PM

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

Info: PHP Manual


#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 22 September 2006 - 04:14 PM

This will work:
$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;

Ronald   8)
RTFM is an almost extinct art form, it should be subsidized.

#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 22 September 2006 - 04:25 PM

so all I had to do was change the "last monday" to "this monday";

ok
Thankx
Tell me the problem, I will try tell you the solution

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 22 September 2006 - 04:31 PM

my little example lol.

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

$convert=strtotime($today)+259200;

$result=date(l,$convert);

echo "But i want $result";

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 22 September 2006 - 06:47 PM

ahh, well this is wha I got

<?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);

?>

Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users