PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
// Count number of days between two dates
function days($endDate, $beginDate)
{
//explode the date by "-" and storing to array
$date_parts1 = explode("-", $beginDate);
$date_parts2 = explode("-", $endDate);
//gregoriantojd() Converts a Gregorian date to Julian Day Count
$start_date = gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
$end_date = gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
return $end_date - $start_date;
}
// Age from birthday
function get_age($bday)
{
$no_of_days = days(date("Y-m-d"), $bday);
$years = $no_of_days / 365;
$round_off = explode(".", $years);
return $round_off[0];
}
echo get_age('1986-06-22');
?>
//n* arguments by default will give age as of now. If given you can see what age is in any given moment.
function getAgeByDate ($iMonth, $iDay, $iYear, $nMonth=0, $nDay=0, $nYear=0) {
$now = time();
date_default_timezone_set('Europe/Sofia');
if (!$nMonth) $nMonth = date("m",$now);
if (!$nDay) $nDay = date("d",$now);
if (!$nYear) $nYear = date("Y",$now);
$baseyear = $nYear - $iYear - 1;
If ($iMonth < $nMonth OR ($iMonth == $nMonth AND $iDay <= $nDay)) {
// had birthday
$baseyear++;
}
return $baseyear;
}
//n* arguments by default will give age as of now. If given you can see what age is in any given moment.
function getAgeByDate ($iMonth, $iDay, $iYear, $nMonth=0, $nDay=0, $nYear=0) {
$now = time();
date_default_timezone_set('Europe/Sofia');
if (!$nMonth) $nMonth = date("m",$now);
if (!$nDay) $nDay = date("d",$now);
if (!$nYear) $nYear = date("Y",$now);
$baseyear = $nYear - $iYear - 1;
If ($iMonth < $nMonth OR ($iMonth == $nMonth AND $iDay <= $nDay)) {
// had birthday
$baseyear++;
}
return $baseyear;
}
this works with INDIA ?
i didnt find the Time ZONE code for this on php.net
jmut wrote:Remove date_default_timezone_set() call and try. It's just there cause it's strict warning.
Well, is India special when it comes to dates/calendar?