Re: [PHP] Re: strtotime

2010-10-18 Thread Tamara Temple


On Oct 17, 2010, at 9:57 PM, Tommy Pham wrote:


-Original Message-
From: Tamara Temple [mailto:tamouse.li...@gmail.com]
On Oct 17, 2010, at 2:34 PM, John Taylor-Johnston wrote:


Here is another nifty piece of code I found. How does this work?
What is 31556926?


Number of second in a year? (31556926 / (24 * 60 * 60) yields
365.2421...)



Your forgot to divide 365.25 days per year ;)

well, no i didn't forget, merely pointing out that it equals days in a  
year.



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



Re: [PHP] Re: strtotime

2010-10-18 Thread Richard Quadling
On 17 October 2010 20:34, John Taylor-Johnston
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:
 Yaay, I'm 45 now :).

Happy Birthday. ;-)
-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



Re: [PHP] Re: strtotime

2010-10-17 Thread Tamara Temple


On Oct 17, 2010, at 12:58 AM, John Taylor-Johnston wrote:


According to this, I'm 44 not 45 :)p

$birthday = '1965-08-30';

//calculate years of age (input string: -MM-DD)

function birthday ($birthday){
  list($year,$month,$day) = explode(-,$birthday);
  $year_diff  = date(Y) - $year;
  $month_diff = date(m) - $month;
  $day_diff   = date(d) - $day;
  if ($day_diff  0 || $month_diff  0)


This will trigger anytime the current day of the month is less than 30.


$year_diff--;
  return $year_diff;
}

echo birthday ($birthday);




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



RE: [PHP] Re: strtotime

2010-10-17 Thread Tommy Pham
 -Original Message-
 From: John Taylor-Johnston [mailto:John.Taylor-
 johns...@cegepsherbrooke.qc.ca]
 Sent: Saturday, October 16, 2010 10:58 PM
 To: PHP-General
 Subject: [PHP] Re: strtotime
 
 According to this, I'm 44 not 45 :)p
 
 $birthday = '1965-08-30';
 
 //calculate years of age (input string: -MM-DD)
 
function birthday ($birthday){
  list($year,$month,$day) = explode(-,$birthday);
  $year_diff  = date(Y) - $year;
  $month_diff = date(m) - $month;
  $day_diff   = date(d) - $day;
  if ($day_diff  0 || $month_diff  0)

I think the problem is with the logic above.

$year_diff = 44
$month_diff = 2
$day_diff = -13

Since the $month_diff is positive meaning you're already passed your
birthdate.  If the $month_diff is 0 - your birth month, then you need to
check if the if it's past your birth day yet (negative $day_diff).

That logic should be changed to if if (($month_diff == 0  $day_diff  0)
|| $month_diff  0)

Then you're 45 ;)

Regards,
Tommy

$year_diff--;
  return $year_diff;
}
 
 echo birthday ($birthday);
 
 
 
 John Taylor-Johnston wrote:
  I'm working my way right now through the manual:
  http://ca.php.net/manual/en/function.strtotime.php.
 
 


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



Re: [PHP] Re: strtotime

2010-10-17 Thread John Taylor-Johnston

Yaay, I'm 45 now :).

Here is another nifty piece of code I found. How does this work? What is 
31556926?


function calculateAge($birthday){
return floor((time() - strtotime($birthday))/31556926);
}

echo calculateAge('1965-10-17');

http://ca.php.net/manual/en/function.floor.php

--
$birthday = '1965-08-30';

//calculate years of age (input string: -MM-DD)

  function birthday ($birthday){
list($year,$month,$day) = explode(-,$birthday);
$year_diff  = date(Y) - $year;
$month_diff = date(m) - $month;
$day_diff   = date(d) - $day;
#  if ($day_diff  0 || $month_diff  0)
if (($month_diff == 0  $day_diff  0) || $month_diff  0)
  $year_diff--;
return $year_diff;
  }

echo birthday ($birthday);


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



Re: [PHP] Re: strtotime

2010-10-17 Thread richard gray

 On 17/10/2010 21:34, John Taylor-Johnston wrote:

Yaay, I'm 45 now :).

Here is another nifty piece of code I found. How does this work? What 
is 31556926?




number of seconds in a year...?

Rich

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



Re: [PHP] Re: strtotime

2010-10-17 Thread Tamara Temple


On Oct 17, 2010, at 2:34 PM, John Taylor-Johnston wrote:

Here is another nifty piece of code I found. How does this work?  
What is 31556926?


Number of second in a year? (31556926 / (24 * 60 * 60) yields  
365.2421...)



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



RE: [PHP] Re: strtotime

2010-10-17 Thread Tommy Pham
 -Original Message-
 From: Tamara Temple [mailto:tamouse.li...@gmail.com]
 Sent: Sunday, October 17, 2010 2:33 PM
 To: PHP General
 Subject: Re: [PHP] Re: strtotime
 
 
 On Oct 17, 2010, at 2:34 PM, John Taylor-Johnston wrote:
 
  Here is another nifty piece of code I found. How does this work?
  What is 31556926?
 
 Number of second in a year? (31556926 / (24 * 60 * 60) yields
 365.2421...)
 
 
Your forgot to divide 365.25 days per year ;)


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



[PHP] Re: strtotime

2010-10-16 Thread John Taylor-Johnston

According to this, I'm 44 not 45 :)p

$birthday = '1965-08-30';

//calculate years of age (input string: -MM-DD)

  function birthday ($birthday){
list($year,$month,$day) = explode(-,$birthday);
$year_diff  = date(Y) - $year;
$month_diff = date(m) - $month;
$day_diff   = date(d) - $day;
if ($day_diff  0 || $month_diff  0)
  $year_diff--;
return $year_diff;
  }

echo birthday ($birthday);



John Taylor-Johnston wrote:
I'm working my way right now through the manual: 
http://ca.php.net/manual/en/function.strtotime.php.





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



[PHP] Re: strtotime - assumptions about default formatting of dates

2009-12-24 Thread Pete Ford

On 24/12/09 12:20, Angus Mann wrote:

Hi all. I need to allow users to enter dates and times, and for a while now 
I've been forcing them to use javascript date/time pickers so I can be 
absolutely sure the formatting is correct.

Some users are requesting to be able to type the entries themselves so I've 
decided to allow this.

I'm in Australia, and the standard formatting of dates here is DD/MM/ or 
DD-MM-

I recognize this is different to what seems to happen in the US, where it is 
MM/DD/ or MM-DD-

When I process an entered date using strtotime() it seems to work fine.

But of course I am concerned when dates like January 2 come up.

I find that 2/1/2009 is interpreted as January 2, 2009 on my installation, 
which is Windows 7 with location set to Australia.

But can I be sure that all installations of PHP, perhaps in different countries 
and on different operating systems will interpret dates the same?

I can't find much mention of this question online or in the manual.

Any help much appreciated.
Angus



I wrote a little AJAX gadget which sent the string typed to a PHP backend which 
parsed it using strtotime and then formatting it out again as something 
unamiguous (like 2 January 2009). Then every time the date entry field is 
changed by the user (with an onKeyUp event), this AJAX call is triggered and 
displays the unambiguous form next to the input box, so users can see how their 
entry is being interpreted.

Of course, there's some overhead in the AJAX calls, and it requires JavaScript.

If you wanted to do without JavaScript you could do a similar parse-format 
sequence when the form is submitted and show a confirmation page with your 
server's interpretation of the date.


Cheers
Pete

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



Re: [PHP] Re: strtotime - assumptions about default formatting of dates

2009-12-24 Thread Angus Mann
I wrote a little AJAX gadget which sent the string typed to a PHP backend 
which parsed it using strtotime and then formatting it out again as 
something unamiguous (like 2 January 2009). Then every time the date entry 
field is changed by the user (with an onKeyUp event), this AJAX call is 
triggered and displays the unambiguous form next to the input box, so 
users can see how their entry is being interpreted.
Of course, there's some overhead in the AJAX calls, and it requires 
JavaScript.


If you wanted to do without JavaScript you could do a similar parse-format 
sequence when the form is submitted and show a confirmation page with your 
server's interpretation of the date.


Cheers
Pete


I took this idea and wrote an ajax so that on keyup or blur, the entry is 
sent to PHP which puts it into strtotime() and if a valid result comes out, 
formats it something like Wed January 23, 2008 6:23pm. If the result is 
invalid, it outputs an Invalid message. This is then displayed in a span 
next to the textbox.


So as the user types they can see if what they entered is valid, and also 
see how the date/time will be interpreted. Works beautifully, and makes the 
form very usable.


For what it's worth, here is the code:
The PHP ajax (called judgedatetime.php:
---
$inp=$_REQUEST['a'];
$a=strtotime($inp);
if ($a  1200103200){
$b=Invalid;
} else {
$b=date(D M j, Y g:ia,$a);
}
echo $b;
?


The Javascript
---
function assessdtime(dTime,putHere){
AjaxRequest.get({'url':'ajax/judgedatetime.php',
 'parameters':{'a':dTime},
 'onSuccess':function(req){
  document.getElementById(putHere).innerHTML=req.responseText;
}
})}

And HTML embedded in the page..
---
input type=text size=14 id=start name=start 
onkeyup=assessdtime(this.value,'startreport'); 
onblur=assessdtime(this.value,'startreport');  /
span id=startreportEnter a date and time/span 



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



Re: [PHP] Re: strtotime

2008-11-09 Thread gilles

Lester Caine [EMAIL PROTECTED] a écrit dans le message de news: 
[EMAIL PROTECTED]
 Ashley Sheridan wrote:
 I'll translate

 In PHP4, strtotime works fine

 in PHP5 strtotime gives a result of 19700101 when the data entered was
 strtotime(20080950)


 What does work fine mean?  20080950 isn't normal, so what is the
 expected result?

 Well, for starts Micah is right, your date string will be interpreted as
 the 50th of September, 2008, which isn't valid and defaults to the time
 represented by the timestamp 0. If you want to turn 8-digit number
 strings into timestamps, make sure of two things:

 1.It's actually a string and not a number
 2.The string is in the format mmdd

 The strings can be a variety of formats, all found at
 http://www.gnu.org/software/shishi/manual/html_node/Date-input-formats.html 
 which is a link available on the strtotime manual page.

 I seem to remember a previous discussion about this 'bug' but I can't 
 track the notes. Is it not the case that you can simply add days or months 
 to the 'number' and then use strtotime to output the 'normalised' date. So 
 adding 30 to 20th Sept would return 20th October. This very useful feature 
 was corrected as a bug in the rewrite of Date in PHP5.1?
 Reason for looking for the notes was to remember how one has to do it now 
 

 -- 
 Lester Caine - G8HFL
Thanks everybody for your answer. Yes, this is a very useful feature to add 
days in a date.
My version of PHP is 5.2.0
Fx GILLES 



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



Re: [PHP] Re: strtotime

2008-11-09 Thread Thodoris

O/H Bastien Koert ??:

2008/11/8 Maciek Sokolewicz [EMAIL PROTECTED]

  

gilles wrote:



Avec la version 4 de php, strtotime(20080950) fonctionne correctement en
allant sur le mois d'octobre, alors qu'en version 5: 19700101.
Merci de votre aide


  

This is an ENGLISH list, please rephrase your question in english and
people might understand.

Cette liste est une liste anglaise, reformulent svp votre question en
anglais svp.

merci,

- Tul


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




I'll translate

In PHP4, strtotime works fine
  


Define works  fine.


in PHP5 strtotime gives a result of 19700101 when the data entered was
strtotime(20080950)

  


Linux
PHP version 5.1.6
Apache 2

This strtotime(20080950) returns nothing.

---
Thodoris





Re: [PHP] Re: strtotime

2008-11-09 Thread Thodoris

O/H gilles έγραψε:
Thodoris [EMAIL PROTECTED] a ιcrit dans le message de news: 
[EMAIL PROTECTED]
  

O/H Bastien Koert ??:


2008/11/8 Maciek Sokolewicz [EMAIL PROTECTED]


  

gilles wrote:



Avec la version 4 de php, strtotime(20080950) fonctionne correctement 
en

allant sur le mois d'octobre, alors qu'en version 5: 19700101.
Merci de votre aide



  

This is an ENGLISH list, please rephrase your question in english and
people might understand.

Cette liste est une liste anglaise, reformulent svp votre question en
anglais svp.

merci,

- Tul


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





I'll translate

In PHP4, strtotime works fine

  

Define works  fine.



in PHP5 strtotime gives a result of 19700101 when the data entered was
strtotime(20080950)


  

Linux
PHP version 5.1.6
Apache 2

This strtotime(20080950) returns nothing.

---
Thodoris

Works fine in php4 means date(d/m/Y,strtotime(20080950)) returns 
20/10/2008, which is correct.
Thanks 




  


In another server this:

?php
$tstamp = date(d/m/Y,strtotime(20080950));

print pre;
print $tstamp;
?

gives me:
01/01/1970

Funny isn't it? I gives me the epoch start date. Probably because 
strtotime returns null so date thinks that null is equivalent to 0 or 
something like that AFAIK.


Nevertheless this 20080950 is not a valid date so this behavior makes 
more sense to me than getting 20/10/2008 as a result. So any invalid 
date will probably give you 01/01/1970.






Re: [PHP] Re: strtotime

2008-11-09 Thread Ashley Sheridan
On Sun, 2008-11-09 at 19:46 +0100, gilles wrote:
 Thodoris [EMAIL PROTECTED] a crit dans le message de news: 
 [EMAIL PROTECTED]
  O/H Bastien Koert ??:
  2008/11/8 Maciek Sokolewicz [EMAIL PROTECTED]
 
 
  gilles wrote:
 
 
  Avec la version 4 de php, strtotime(20080950) fonctionne correctement 
  en
  allant sur le mois d'octobre, alors qu'en version 5: 19700101.
  Merci de votre aide
 
 
 
  This is an ENGLISH list, please rephrase your question in english and
  people might understand.
 
  Cette liste est une liste anglaise, reformulent svp votre question en
  anglais svp.
 
  merci,
 
  - Tul
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
  I'll translate
 
  In PHP4, strtotime works fine
 
 
  Define works  fine.
 
  in PHP5 strtotime gives a result of 19700101 when the data entered was
  strtotime(20080950)
 
 
 
  Linux
  PHP version 5.1.6
  Apache 2
 
  This strtotime(20080950) returns nothing.
 
  ---
  Thodoris
 Works fine in php4 means date(d/m/Y,strtotime(20080950)) returns 
 20/10/2008, which is correct.
 Thanks 
 
 
 
Which is actually incorrect (I've never seen the 50th of September) and
it was fixed in PHP 5. What you are assuming is correct behaviour is
actually a bug.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Re: strtotime

2008-11-09 Thread Eric Butera
On Sun, Nov 9, 2008 at 3:50 PM, Ashley Sheridan
[EMAIL PROTECTED] wrote:
 On Sun, 2008-11-09 at 19:46 +0100, gilles wrote:
 Thodoris [EMAIL PROTECTED] a crit dans le message de news:
 [EMAIL PROTECTED]
  O/H Bastien Koert ??:
  2008/11/8 Maciek Sokolewicz [EMAIL PROTECTED]
 
 
  gilles wrote:
 
 
  Avec la version 4 de php, strtotime(20080950) fonctionne correctement
  en
  allant sur le mois d'octobre, alors qu'en version 5: 19700101.
  Merci de votre aide
 
 
 
  This is an ENGLISH list, please rephrase your question in english and
  people might understand.
 
  Cette liste est une liste anglaise, reformulent svp votre question en
  anglais svp.
 
  merci,
 
  - Tul
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
  I'll translate
 
  In PHP4, strtotime works fine
 
 
  Define works  fine.
 
  in PHP5 strtotime gives a result of 19700101 when the data entered was
  strtotime(20080950)
 
 
 
  Linux
  PHP version 5.1.6
  Apache 2
 
  This strtotime(20080950) returns nothing.
 
  ---
  Thodoris
 Works fine in php4 means date(d/m/Y,strtotime(20080950)) returns
 20/10/2008, which is correct.
 Thanks



 Which is actually incorrect (I've never seen the 50th of September) and
 it was fixed in PHP 5. What you are assuming is correct behaviour is
 actually a bug.


 Ash
 www.ashleysheridan.co.uk


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



I didn't read this thread (sorry) but I wonder if timezone/locale
might be the culprit.

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



Re: [PHP] Re: strtotime

2008-11-09 Thread gilles

Thodoris [EMAIL PROTECTED] a écrit dans le message de news: 
[EMAIL PROTECTED]
 O/H Bastien Koert ??:
 2008/11/8 Maciek Sokolewicz [EMAIL PROTECTED]


 gilles wrote:


 Avec la version 4 de php, strtotime(20080950) fonctionne correctement 
 en
 allant sur le mois d'octobre, alors qu'en version 5: 19700101.
 Merci de votre aide



 This is an ENGLISH list, please rephrase your question in english and
 people might understand.

 Cette liste est une liste anglaise, reformulent svp votre question en
 anglais svp.

 merci,

 - Tul


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



 I'll translate

 In PHP4, strtotime works fine


 Define works  fine.

 in PHP5 strtotime gives a result of 19700101 when the data entered was
 strtotime(20080950)



 Linux
 PHP version 5.1.6
 Apache 2

 This strtotime(20080950) returns nothing.

 ---
 Thodoris
Works fine in php4 means date(d/m/Y,strtotime(20080950)) returns 
20/10/2008, which is correct.
Thanks 



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



[PHP] Re: strtotime

2008-11-08 Thread Maciek Sokolewicz

gilles wrote:
Avec la version 4 de php, strtotime(20080950) fonctionne correctement en 
allant sur le mois d'octobre, alors qu'en version 5: 19700101.
Merci de votre aide 





This is an ENGLISH list, please rephrase your question in english and 
people might understand.


Cette liste est une liste anglaise, reformulent svp votre question en 
anglais svp.


merci,

- Tul

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



Re: [PHP] Re: strtotime

2008-11-08 Thread Bastien Koert
2008/11/8 Maciek Sokolewicz [EMAIL PROTECTED]

 gilles wrote:

 Avec la version 4 de php, strtotime(20080950) fonctionne correctement en
 allant sur le mois d'octobre, alors qu'en version 5: 19700101.
 Merci de votre aide


 This is an ENGLISH list, please rephrase your question in english and
 people might understand.

 Cette liste est une liste anglaise, reformulent svp votre question en
 anglais svp.

 merci,

 - Tul


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


I'll translate

In PHP4, strtotime works fine

in PHP5 strtotime gives a result of 19700101 when the data entered was
strtotime(20080950)

-- 

Bastien

Cat, the other other white meat


Re: [PHP] Re: strtotime

2008-11-08 Thread Micah Gersten
Bastien Koert wrote:
 2008/11/8 Maciek Sokolewicz [EMAIL PROTECTED]

   
 gilles wrote:

 
 Avec la version 4 de php, strtotime(20080950) fonctionne correctement en
 allant sur le mois d'octobre, alors qu'en version 5: 19700101.
 Merci de votre aide


   
 This is an ENGLISH list, please rephrase your question in english and
 people might understand.

 Cette liste est une liste anglaise, reformulent svp votre question en
 anglais svp.

 merci,

 - Tul


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


 
 I'll translate

 In PHP4, strtotime works fine

 in PHP5 strtotime gives a result of 19700101 when the data entered was
 strtotime(20080950)

   
What does work fine mean?  20080950 isn't normal, so what is the
expected result?

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



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



Re: [PHP] Re: strtotime

2008-11-08 Thread Ashley Sheridan
On Sat, 2008-11-08 at 18:57 -0600, Micah Gersten wrote:
 Bastien Koert wrote:
  2008/11/8 Maciek Sokolewicz [EMAIL PROTECTED]
 

  gilles wrote:
 
  
  Avec la version 4 de php, strtotime(20080950) fonctionne correctement en
  allant sur le mois d'octobre, alors qu'en version 5: 19700101.
  Merci de votre aide
 
 

  This is an ENGLISH list, please rephrase your question in english and
  people might understand.
 
  Cette liste est une liste anglaise, reformulent svp votre question en
  anglais svp.
 
  merci,
 
  - Tul
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
  
  I'll translate
 
  In PHP4, strtotime works fine
 
  in PHP5 strtotime gives a result of 19700101 when the data entered was
  strtotime(20080950)
 

 What does work fine mean?  20080950 isn't normal, so what is the
 expected result?
 
 Thank you,
 Micah Gersten
 onShore Networks
 Internal Developer
 http://www.onshore.com
 
 
 
Well, for starts Micah is right, your date string will be interpreted as
the 50th of September, 2008, which isn't valid and defaults to the time
represented by the timestamp 0. If you want to turn 8-digit number
strings into timestamps, make sure of two things:

1.It's actually a string and not a number
2.The string is in the format mmdd

The strings can be a variety of formats, all found at
http://www.gnu.org/software/shishi/manual/html_node/Date-input-formats.html 
which is a link available on the strtotime manual page.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Re: strtotime

2008-11-08 Thread Lester Caine

Ashley Sheridan wrote:

I'll translate

In PHP4, strtotime works fine

in PHP5 strtotime gives a result of 19700101 when the data entered was
strtotime(20080950)

  

What does work fine mean?  20080950 isn't normal, so what is the
expected result?



Well, for starts Micah is right, your date string will be interpreted as
the 50th of September, 2008, which isn't valid and defaults to the time
represented by the timestamp 0. If you want to turn 8-digit number
strings into timestamps, make sure of two things:

1.It's actually a string and not a number
2.The string is in the format mmdd

The strings can be a variety of formats, all found at
http://www.gnu.org/software/shishi/manual/html_node/Date-input-formats.html 
which is a link available on the strtotime manual page.


I seem to remember a previous discussion about this 'bug' but I can't track 
the notes. Is it not the case that you can simply add days or months to the 
'number' and then use strtotime to output the 'normalised' date. So adding 30 
to 20th Sept would return 20th October. This very useful feature was corrected 
as a bug in the rewrite of Date in PHP5.1?

Reason for looking for the notes was to remember how one has to do it now 

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



[PHP] Re: strtotime problem

2008-10-08 Thread Nathan Rixham

Thodoris wrote:
I know that *strtotime*() only recognises the formats mm/dd/, 
-mm-dd and mmdd

for numeric months but I need do something like that:

function dateWebToMysql($webdate){

$format = 'Y-m-d';
$timestamp = strtotime($webdate);

return date($format,$timestamp);

}


print dateWebToMysql('01/03/2008');

Where 01/03/2008 is in dd/mm/ format (not the American format). What 
is the best way of doing this?


Any ideas?



completely random and never used myself [ie just made it up]

function dateWebToMysql( $webdate ){
 return strtotime(strrev( str_replace('/','', $webdate) ));
}

--
nathan ( [EMAIL PROTECTED] )
{
  Senior Web Developer
  php + java + flex + xmpp + xml + ecmascript
  web development edinburgh | http://kraya.co.uk/
}

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



Re: [PHP] Re: strtotime problem

2008-10-08 Thread Stut

On 8 Oct 2008, at 12:42, Nathan Rixham wrote:

Thodoris wrote:
I know that *strtotime*() only recognises the formats mm/dd/,  
-mm-dd and mmdd

for numeric months but I need do something like that:
function dateWebToMysql($webdate){
   $format = 'Y-m-d';
   $timestamp = strtotime($webdate);
   return date($format,$timestamp);
   }
print dateWebToMysql('01/03/2008');
Where 01/03/2008 is in dd/mm/ format (not the American format).  
What is the best way of doing this?

Any ideas?


completely random and never used myself [ie just made it up]

function dateWebToMysql( $webdate ){
return strtotime(strrev( str_replace('/','', $webdate) ));
}


What exactly do you expect strtotime('80023010') to return?

I tend to always normalise dates to Y-m-d before pushing them into  
strtotime, but in your case you don't need to do that. If you *know*  
the date always comes in as that format you can simply do this...


function dateWebToMysql($webdate)
{
list($day, $month, $year) = explode('/', $webdate);
return $year.'-'.$month.'-'.$day;
}

-Stut

--
http://stut.net/

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



[PHP] Re: strtotime

2008-02-10 Thread Ron Piggott
I see I broke a rule.  The variable can't start with a number.  Still
strtotime doesn't work with -18 months   How would you handle this?  Ron

On Sun, 2008-02-10 at 06:46 -0500, Ron Piggott wrote:
 I am trying to calculate what was the date 18 months ago.  When I give
 the command:
 
 $18_months_ago = strtotime(-18 months);
 
 It comes back with: 
 
 Parse error: parse error, unexpected T_LNUMBER, expecting T_VARIABLE
 
 How would you calculate 18 months ago from today?
 
 Ron
-- 
[EMAIL PROTECTED] 
www.actsministrieschristianevangelism.org 

Acts Ministries Christian Evangelism 
Where People Matter 
12 Burton Street 
Belleville, Ontario, Canada   K8P 1E6 
 
In Belleville Phone : (613) 967-0032 
In North America Call Toll Free : (866) ACTS-MIN 
Fax: (613) 967-9963 

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



Re: [PHP] Re: strtotime

2008-02-10 Thread Per Jessen
Ron Piggott wrote:

 I see I broke a rule.  The variable can't start with a number.  Still
 strtotime doesn't work with -18 months   How would you handle this? 
 Ron

Uh, it works fine here: 

php5 -r '$a=strtotime(-18 months); print strftime(%Y%m%d,$a); ':

20060810



/Per Jessen, Zürich

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



[PHP] Re: Strtotime returns 02/09/2008 for next Saturday....

2008-01-31 Thread Nathan Rixham

Mike Morton wrote:

I have been using:

$nextSaturday= date(m/d/Y,strtotime(next saturday));

For months long time now with out problems, but in the last two days, it
went kind of funky.  It is now returning:

02/09/2008 instead of the expected 02/02/2008.  I have tried the same code
on another server and different version of PHP,and it works ok.

More info:

Shell date: Thu Jan 31 09:44:50 EST 2008
echo date(Y-m-d g:i A T, time()); = 2008-01-31 10:00 AM EST
echo date(Y-m-d g:i A T, strtotime(next saturday)); = 2008-02-09 12:00
AM EST

version: 4.3.9  (highest version we can have at the moment)

I could not find this in the known bugs from this version

So - is this something that is server or version specific?

TIA!


from the manual page on php.net for strtotime

Warning

In PHP versions prior to 4.4.0, next is incorrectly computed as +2. A 
typical solution to this is to use +1.


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



[PHP] Re: strtotime

2006-10-25 Thread Ivo F.A.C. Fokkema
On Tue, 24 Oct 2006 20:36:08 -0400, Ron Piggott (PHP) wrote:

 
 I have used the strtotime command to calculate a week ago (among other
 things) with syntax like this:
 
 $one_week_ago = strtotime(-7 days);
 $one_week_ago = date('Y-m-d', $one_week_ago);
 
 How would you use this command to figure out the last day of the month
 in two months from now --- Today is October 24th 2006; the results I am
 trying to generate are December 31st 2006.  I want to keep the same
 result until the end of October and then on November 1st and throughout
 November the result to be January 31st 2007
 
 Ron

My suggestion is:

$date = date('Y-m-t', strtotime('+2 months'));
$date = date('F jS Y', strtotime($date));

Only two lines of code, only four function calls. As you know, there are
many ways to do a thing.

Ivo

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



[PHP] Re: strtotime() bug?

2005-04-04 Thread Al
Al wrote:
Suddenly my strtotime() are goofy, anyone have any ideas?
echo date('Y/m/d/H', time()). br;//2005/04/04/18
echo date('Y/m/d/H', strtotime(-1 day)). br;
//2005/04/03/18
echo date('Y/m/d/H', strtotime(last Sunday)). br;
//2005/04/02/23

Sunday shows as Saturday.

Additional info
Problem seems to be daylight saving time problem
echo date('Y/m/d/H:i:s', strtotime(last sunday));   //2005/04/02/23:00:00
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: strtotime failure

2002-05-07 Thread David Robley

In article [EMAIL PROTECTED], 
[EMAIL PROTECTED] says...
 Hallo,
 
 Why would strtotime fail (i.e. return a -1)?  I check the type with gettype,
 which tells me that the argument I'm passing in is a string.  I cast it to a
 string before passing it in, with the same results (returns a -1).  The only
 thing that seems to do anything is to settype it to string before calling
 strtotime, which ends up with bizarre results.
 
 The arguments I'm passing in are, for example 11:00, 13:00, 14:30, etc, and
 are coming out of a database.  Only SOME of this data results in a -1 when I
 call strtotime on it.  Other records (the same numbers - 11:00, 13:00, etc.)
 come out fine.
 
 Could the data that's failing strtotime have been corrupted on data-entry?
 Why does is_string on this data tell me it's a string?
 
 --Jennifer Koenig
 
For a first guess, try using trim or chop on the data before feeding it to 
strtotime, in case there are unexpected white spaces in the data.

-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

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




[PHP] Re: strtotime failure

2002-05-07 Thread George Nicolae

strtotime returns a timestamp of a data type(ex 05/07/2002)
strtotime(05/07/2002)

you can't recevie a timpstamp from a time of a day.

--


Best regards,
George Nicolae
IT Manager
___
PaginiWeb.com  - Professional Web Design
www.PaginiWeb.com


Jennifer Koenig [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hallo,

 Why would strtotime fail (i.e. return a -1)?  I check the type with
gettype,
 which tells me that the argument I'm passing in is a string.  I cast it to
a
 string before passing it in, with the same results (returns a -1).  The
only
 thing that seems to do anything is to settype it to string before
calling
 strtotime, which ends up with bizarre results.

 The arguments I'm passing in are, for example 11:00, 13:00, 14:30, etc,
and
 are coming out of a database.  Only SOME of this data results in a -1 when
I
 call strtotime on it.  Other records (the same numbers - 11:00, 13:00,
etc.)
 come out fine.

 Could the data that's failing strtotime have been corrupted on data-entry?
 Why does is_string on this data tell me it's a string?

 --Jennifer Koenig



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