[PHP] Re: subtracting dates...

2003-08-02 Thread John Ryan
yeah, i was thinking that before i decided to post to the newsgroup. i
thought there was some simple way of doing it and id be wasting my time.
obviosuly not


Craig Roberts [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Try something along the lines of

 if($current_MM  $MM) {
 $age = $calculatedage - 1;
 }

 you'll also need to do something like this with the day of the month if
the
 user's bday is in the current month.
 at least... i think that works out :$
 Craig Roberts


 John Ryan [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  Hi,
 
  In mySQL, I store dates as -MM-DD, a standard DATE type. It stores
 users
  date of births. I need to calculate in a PHP script, the users age from
 this
  DOB. I get a PHP date in the same format as the mySQL and subtract,
which
  returns the year rounded off. ie, it doesnt matter if your birthdays in
 june
  of 1983 and the date is januray 2003, your age is still returned as 20,
 when
  it should be 19.
 
  Does anyone know how can i get the right age?
 
 





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



[PHP] Re: subtracting dates...

2003-08-02 Thread Craig Roberts
Another idea (slightly simpler)...

how about using mktime(); to create a timestamp from your date info, and
subtract that from the current timestamp - leaving (i think) the person's
age in seconds...

Then just do some math...

hmm... is that really simpler? well it seemed it when i started typing

craig :)
John Ryan [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 yeah, i was thinking that before i decided to post to the newsgroup. i
 thought there was some simple way of doing it and id be wasting my time.
 obviosuly not


 Craig Roberts [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  Try something along the lines of
 
  if($current_MM  $MM) {
  $age = $calculatedage - 1;
  }
 
  you'll also need to do something like this with the day of the month if
 the
  user's bday is in the current month.
  at least... i think that works out :$
  Craig Roberts
 
 
  John Ryan [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
   Hi,
  
   In mySQL, I store dates as -MM-DD, a standard DATE type. It stores
  users
   date of births. I need to calculate in a PHP script, the users age
from
  this
   DOB. I get a PHP date in the same format as the mySQL and subtract,
 which
   returns the year rounded off. ie, it doesnt matter if your birthdays
in
  june
   of 1983 and the date is januray 2003, your age is still returned as
20,
  when
   it should be 19.
  
   Does anyone know how can i get the right age?
  
  
 
 





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



[PHP] Re: subtracting dates...

2003-08-02 Thread Paul Chvostek
On Sat, Aug 02, 2003 at 08:30:34PM +0100, John Ryan wrote:

 In mySQL, I store dates as -MM-DD, a standard DATE type. It stores users
 date of births. I need to calculate in a PHP script, the users age from this
 DOB. I get a PHP date in the same format as the mySQL and subtract, which
 returns the year rounded off. ie, it doesnt matter if your birthdays in june
 of 1983 and the date is januray 2003, your age is still returned as 20, when
 it should be 19.

The function you're probably looking for is floor().

 Does anyone know how can i get the right age?

One quick way would be simple subtraction:

  $old = 1973-06-02;
  $new = 2003-08-02;
  $year = 60*60*24*365.25; // seconds in a year
  $age = strtotime($new) - strtotime($old);
  print Age in years:  . floor($age / $year) . \n;

But you'll run into infrequent problems surrounding leap years.  I'm
sure there's a more accurate way to do this, perhaps even using MySQL's
somewhat more advanced (and less timestamp-centric) date calculation
functions, but this is what I can come up with on short notice.

Note that strtotime will give NEGATIVE TIMESTAMPS for dates earlier than
Jan 1st 1970 at midnight GMT, so this still works for folks over 33.  ;)

-- 
  Paul Chvostek [EMAIL PROTECTED]
  it.canadahttp://www.it.ca/
  Free PHP web hosting!http://www.it.ca/web/


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



[PHP] Re: subtracting dates...

2003-08-02 Thread Craig Roberts
Try something along the lines of

if($current_MM  $MM) {
$age = $calculatedage - 1;
}

you'll also need to do something like this with the day of the month if the
user's bday is in the current month.
at least... i think that works out :$
Craig Roberts


John Ryan [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi,

 In mySQL, I store dates as -MM-DD, a standard DATE type. It stores
users
 date of births. I need to calculate in a PHP script, the users age from
this
 DOB. I get a PHP date in the same format as the mySQL and subtract, which
 returns the year rounded off. ie, it doesnt matter if your birthdays in
june
 of 1983 and the date is januray 2003, your age is still returned as 20,
when
 it should be 19.

 Does anyone know how can i get the right age?





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



[PHP] Re: Subtracting dates in php

2003-07-01 Thread Shivanischal A
try  http://www.phpclasses.org

-shiva



Mike Mannakee [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Anyone know of an easy way to add or subtract dates in php the way you can
 in mysql?  Easier, that is, than coding the logic by hand?  This seems
like
 a total pain.

 Mike





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