onlyican Posted September 22, 2006 Share Posted September 22, 2006 Hey guysI am working on some codeand I want to get the date of Monday and the Date of Sunday for where the week is XI 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 is2006-09-221970-01-05now, the monday of this week is not 5 January 1970So how would I work out the date for Monday and Sunday of a given dateCan anyone help me out hereCheers Quote Link to comment https://forums.phpfreaks.com/topic/21679-the-monday-for-the-week-holding-27-july/ Share on other sites More sharing options...
ober Posted September 22, 2006 Share Posted September 22, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/21679-the-monday-for-the-week-holding-27-july/#findComment-96807 Share on other sites More sharing options...
ronverdonk Posted September 22, 2006 Share Posted September 22, 2006 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) Quote Link to comment https://forums.phpfreaks.com/topic/21679-the-monday-for-the-week-holding-27-july/#findComment-96812 Share on other sites More sharing options...
onlyican Posted September 22, 2006 Author Share Posted September 22, 2006 so all I had to do was change the "last monday" to "this monday";okThankx Quote Link to comment https://forums.phpfreaks.com/topic/21679-the-monday-for-the-week-holding-27-july/#findComment-96820 Share on other sites More sharing options...
redarrow Posted September 22, 2006 Share Posted September 22, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/21679-the-monday-for-the-week-holding-27-july/#findComment-96826 Share on other sites More sharing options...
onlyican Posted September 22, 2006 Author Share Posted September 22, 2006 ahh, well this is wha I got[code]<?phpfunction 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] Quote Link to comment https://forums.phpfreaks.com/topic/21679-the-monday-for-the-week-holding-27-july/#findComment-96883 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.