Fenhopi Posted November 10, 2010 Share Posted November 10, 2010 I have a form where you can pick all the days in the week. When the form is posted my code finds the date of the day you picked that most recently went by. Then the code takes that date, and echos the date of every day of the week that you picked that comes after that date for a year. But for some reason he thinks we're in 2009, even though i know the date puts out that we're in 2010. Here's the code: <?php //function if(isset($_POST['submit'])) { function nextWeeksDay($date_begin,$nbrweek) { $nextweek=array(); for($i = 1; $i <= $nbrweek; $i++) { // 52 week in one year of course $nextweek[$i]=date('d-m-y', strtotime('+'.$i.' week',$date_begin)); } return $nextweek; } //Get what user posted as day, and find the date of the past day gone. $roday = $_POST['day']; echo $roday; echo date('d-m-y',strtotime('last ' . $roday)); $sistdag = date('d-m-y',strtotime('last ' . $roday)); /// end function /// example of a select date // var $date_begin = strtotime($sistdag); //D Day Month Year - like function format. $nbrweek=52; // call function $result=nextWeeksDay($date_begin,$nbrweek); // Preview for($i = 1; $i <= $nbrweek; $i++) { echo '<br> - '.$result[$i]; } } ?> All help appreciated! Link to comment https://forums.phpfreaks.com/topic/218282-retrieve-date-problem/ Share on other sites More sharing options...
micah1701 Posted November 10, 2010 Share Posted November 10, 2010 its an issue of strtotime converting your date with dashes in it. $date_begin = strtotime($sistdag); // at this point, its converting what you think is d-m-y but it thinks that is y-m-d. if you change $sistdag = date('d-m-y',strtotime('last ' . $roday)); to $sistdag = date('y-m-d',strtotime('last ' . $roday)); it will solve your problem for more info, see also: http://us2.php.net/manual/en/function.strtotime.php#100144 Link to comment https://forums.phpfreaks.com/topic/218282-retrieve-date-problem/#findComment-1132654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.