Page 1 of 1

calculate difference in dates

Posted: Thu Jul 06, 2006 9:42 pm
by alexislalas
i want to get the age of the people. i get it in the form as the date of birth 0000/00/00.


when i do a report, how do i get the age.


thanks...

Posted: Thu Jul 06, 2006 9:52 pm
by Burrito
look at this old post:

viewtopic.php?t=39916&start=0

it's not exactly what you're looking for, but will get you started on the right foot

Posted: Thu Jul 06, 2006 9:53 pm
by csingsaas
You should use something similar to the following to break apart the date into month, day and year elements.


$today = date("Y-m-d");

$d = explode(" ",$today);
$date1 = $d[0];

$date_x = explode("-",$date1);
$year = $date_x[0];
$month = $date_x[1];
$day = $date_x[2];


So if you had the date 2004-06-24, the variables would be set to:

$year = 2004
$month = 06
$day = 24

From here you can perform basic math equations on the variables. Hope this helps.


Regards,
Cody Singsaas
IE Internet Solutions
http://www.ieinternetsolutions.com

Posted: Thu Jul 06, 2006 10:56 pm
by RobertGonzalez
Please, when posting PHP, wrap it in

Code: Select all

bbcode tags.

[quote="csingsaas"]You should use something similar to the following to break apart the date into month, day and year elements. 

[syntax="php"]<?php
$today = date("Y-m-d");

$d = explode(" ",$today);
$date1 = $d[0];

$date_x = explode("-",$date1);
$year = $date_x[0];
$month = $date_x[1];
$day = $date_x[2];
?>
So if you had the date 2004-06-24, the variables would be set to:

Code: Select all

<?php
$year = 2004
$month = 06
$day = 24
?>
From here you can perform basic math equations on the variables. Hope this helps.


Regards,
Cody Singsaas
IE Internet Solutions
http://www.ieinternetsolutions.com[/quote][/syntax]