Jump to content

Retrieve date problem


Fenhopi

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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