[PHP] Problem with strtotime() and 2002-03-31

2002-03-19 Thread John Clarke

I have used the following script successfully for a year now, but have just
found a problem with the date 2002-03-31.
When I add 0 days to this date it returns 2002-03-31.Correct!
When I add 1 day to this date it still returns 2002-03-31.NOT Correct
n I add 2 days to this date it returns 2002-03-31.NOT
correct

So far this is the only date that I havefound a problem with.

Any ideas why this would be happening?

function addDays($date,$nofdays) {
  $dd=strtotime($date);
  $dd2=$dd + (3600*24*$nofdays);
  return date("Y-m-d", $dd2);
}
$nd=addDays("2002-03-31","2");
echo $nd

Regards

John Clarke



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Problem with strtotime() and 2002-03-31

2002-03-19 Thread John Clarke

Thanks guys. You were right. I have been playing around and just found an
extra 3600 seconds on 31/3/2002.!!!

Thats a trap for us young players.

Will develop a creative fix.

Does this mean that there is a day with only 23 hours somewhere Though
this wouldnt cause a problem I guess.

Thanks again,

John


"John Clarke" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I have used the following script successfully for a year now, but have
just
> found a problem with the date 2002-03-31.
> When I add 0 days to this date it returns 2002-03-31.Correct!
> When I add 1 day to this date it still returns 2002-03-31.NOT Correct
> n I add 2 days to this date it returns 2002-03-31.NOT
> correct
>
> So far this is the only date that I havefound a problem with.
>
> Any ideas why this would be happening?
>
> function addDays($date,$nofdays) {
>   $dd=strtotime($date);
>   $dd2=$dd + (3600*24*$nofdays);
>   return date("Y-m-d", $dd2);
> }
> $nd=addDays("2002-03-31","2");
> echo $nd
>
> Regards
>
> John Clarke
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] year 2002 strtotime problem

2001-11-01 Thread John Clarke

I have this problem with Php 4.0.5 on both  Win ME and Linus boxes, where my
year 2002 dates are converted back to 2001 when formating with 'strtotime'.

First I post the following variables from an html page to a php page

$date1='12/12/2001'
$date2='15/01/2002'

I then use date("D M j Y", strtotime($date1);  and date("D M j Y",
strtotime($date2));
to store them in an array for screen display.

As the users have the abilty to selected different dates I need to check
that 1 is before the other.
To do this I have a script timediff() that I pass the two dates to in the
above format.

All works fine until the year 2002 is selected. This is part of the
timediff() code with dispay statements and the result.

 function timediff($date1,$date2) {

   echo 'date1= '."$date1".' ';// displays  'Wed December 12
2001'   ... correct
   echo 'date2= '."$date2".' ';   //  displays   'Tue January 15
2002'   ...correct, all fine so far

$dd1=date("Ymd", strtotime($date1));
$dd2=date("Ymd", strtotime($date2));

   echo 'date1= '.$dd1.'';// displays  '20011212'   ...
correct
   echo 'date2= '.$dd2.' ';   //  displays '20010115
...WRONG
}

It seem that by applying strtotime a 2nd time might cause this problem,
as the first application was fine.

I have tested all possible combinations of strtotime but the year 2002
always goes back to 2001
Have also tried just 'strtotime($date1)' but same problem again.

Any help or comments would be greatly appreciated as I thought I had
finished a booking program any now find this!!

Thanks in anticipation


John Clarke



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] year 2002 strtotime problem

2001-11-01 Thread John Clarke

Even more funny...

I cut and pasted your code and I got;

Wed Dec 12 2001
Sat Mar 1 2003
2001-12-12
2001-03-01

What version of Php and OS are you using??

John

"Niklas lampén" <[EMAIL PROTECTED]> wrote in message
000301c16369$6817a320$ba93c5c3@Niklas">news:000301c16369$6817a320$ba93c5c3@Niklas...
> Funny, I quickly tried this:
>
>  $date1 = "12/12/2001";
> $date2 = "15/01/2002";
>
> $date1 = date("D M j Y", strtotime($date1));
> $date2 = date("D M j Y", strtotime($date2));
>
> print $date1."";
> print $date2."";
>
> print date("Y-m-d", strtotime($date1))."";
> print date("Y-m-d", strtotime($date2))."";
> ?>
>
> And the result was this:
> "
> Wed Dec 12 2001
> Sat Mar 1 2003
> 2001-12-12
> 2003-03-01
> "
>
>
> Niklas
>
>
> -Original Message-
> From: John Clarke [mailto:[EMAIL PROTECTED]]
> Sent: 2. marraskuuta 2001 8:17
> To: [EMAIL PROTECTED]
> Subject: [PHP] year 2002 strtotime problem
>
>
> I have this problem with Php 4.0.5 on both  Win ME and Linus boxes,
> where my year 2002 dates are converted back to 2001 when formating with
> 'strtotime'.
>
> First I post the following variables from an html page to a php page
>
> $date1='12/12/2001'
> $date2='15/01/2002'
>
> I then use date("D M j Y", strtotime($date1);  and date("D M j Y",
> strtotime($date2)); to store them in an array for screen display.
>
> As the users have the abilty to selected different dates I need to check
> that 1 is before the other. To do this I have a script timediff() that I
> pass the two dates to in the above format.
>
> All works fine until the year 2002 is selected. This is part of the
> timediff() code with dispay statements and the result.
>
>  function timediff($date1,$date2) {
>
>echo 'date1= '."$date1".' ';// displays  'Wed
> December 12
> 2001'   ... correct
>echo 'date2= '."$date2".' ';   //  displays   'Tue
> January 15
> 2002'   ...correct, all fine so far
>
> $dd1=date("Ymd", strtotime($date1));
> $dd2=date("Ymd", strtotime($date2));
>
>echo 'date1= '.$dd1.'';// displays  '20011212'
> ...
> correct
>echo 'date2= '.$dd2.' ';   //  displays '20010115
> ...WRONG
> }
>
> It seem that by applying strtotime a 2nd time might cause this
> problem, as the first application was fine.
>
> I have tested all possible combinations of strtotime but the year
> 2002 always goes back to 2001 Have also tried just 'strtotime($date1)'
> but same problem again.
>
> Any help or comments would be greatly appreciated as I thought I had
> finished a booking program any now find this!!
>
> Thanks in anticipation
>
>
> John Clarke
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED] To
> contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] year 2002 strtotime problem

2001-11-01 Thread John Clarke

I'm still running 4.0.5 because that is what my web host is running.
Methinks there may be a problem here.

In the meantime I've tried storing the dates in the array in the original
format in lieu of the fully converted format.
I then reformat the original from the array as required for each page
display or time difference calculation.
This works fine, so I might stick with it.
In hindsight, it is probaly the way I should have gone in the first place as
you pointed out. That way I can play with the date, month and year any way I
want.

Thanks for you input.

John


"Niklas lampén" <[EMAIL PROTECTED]> wrote in message
000401c1636f$fd37d960$ba93c5c3@Niklas">news:000401c1636f$fd37d960$ba93c5c3@Niklas...
Great. :)

I've got PHP 4.0.6 on linux. You?

I think you should break the dates manually, it would be the most sure
way to do it.


Niklas


-Original Message-
From: John Clarke [mailto:[EMAIL PROTECTED]]
Sent: 2. marraskuuta 2001 9:11
To: [EMAIL PROTECTED]
Subject: Re: [PHP] year 2002 strtotime problem


Even more funny...

I cut and pasted your code and I got;

Wed Dec 12 2001
Sat Mar 1 2003
2001-12-12
2001-03-01

What version of Php and OS are you using??

John

"Niklas lampén" <[EMAIL PROTECTED]> wrote in message
000301c16369$6817a320$ba93c5c3@Niklas">news:000301c16369$6817a320$ba93c5c3@Niklas...
> Funny, I quickly tried this:
>
>  $date1 = "12/12/2001";
> $date2 = "15/01/2002";
>
> $date1 = date("D M j Y", strtotime($date1));
> $date2 = date("D M j Y", strtotime($date2));
>
> print $date1."";
> print $date2."";
>
> print date("Y-m-d", strtotime($date1))."";
> print date("Y-m-d", strtotime($date2))."";
> ?>
>
> And the result was this:
> "
> Wed Dec 12 2001
> Sat Mar 1 2003
> 2001-12-12
> 2003-03-01
> "
>
>
> Niklas
>
>
> -Original Message-
> From: John Clarke [mailto:[EMAIL PROTECTED]]
> Sent: 2. marraskuuta 2001 8:17
> To: [EMAIL PROTECTED]
> Subject: [PHP] year 2002 strtotime problem
>
>
> I have this problem with Php 4.0.5 on both  Win ME and Linus boxes,
> where my year 2002 dates are converted back to 2001 when formating
> with 'strtotime'.
>
> First I post the following variables from an html page to a php page
>
> $date1='12/12/2001'
> $date2='15/01/2002'
>
> I then use date("D M j Y", strtotime($date1);  and date("D M j Y",
> strtotime($date2)); to store them in an array for screen display.
>
> As the users have the abilty to selected different dates I need to
> check that 1 is before the other. To do this I have a script
> timediff() that I pass the two dates to in the above format.
>
> All works fine until the year 2002 is selected. This is part of the
> timediff() code with dispay statements and the result.
>
>  function timediff($date1,$date2) {
>
>echo 'date1= '."$date1".' ';// displays  'Wed
> December 12
> 2001'   ... correct
>echo 'date2= '."$date2".' ';   //  displays   'Tue
> January 15
> 2002'   ...correct, all fine so far
>
> $dd1=date("Ymd", strtotime($date1));
> $dd2=date("Ymd", strtotime($date2));
>
>echo 'date1= '.$dd1.'';// displays  '20011212'
> ...
> correct
>echo 'date2= '.$dd2.' ';   //  displays '20010115
> ...WRONG
> }
>
> It seem that by applying strtotime a 2nd time might cause this
> problem, as the first application was fine.
>
> I have tested all possible combinations of strtotime but the year
> 2002 always goes back to 2001 Have also tried just 'strtotime($date1)'

> but same problem again.
>
> Any help or comments would be greatly appreciated as I thought I had
> finished a booking program any now find this!!
>
> Thanks in anticipation
>
>
> John Clarke
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED] To
> contact the list administrators, e-mail: [EMAIL PROTECTED]
>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED] To
contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]