Jump to content

Code for Year Count


talmik

Recommended Posts

Hello all

This bit of code is supposed to count the number of years between a creation date and the current date then place that number of years in the database. I seem to be missing something or have done something wrong. Can anyone see where it all went wrong?

Quote

function GetMemberYears($P_CharacterID)
{
    $Creation = SQL_ReadField("Characters",$P_CharacterID,"CreationDate");
    $CreationExpand = explode("/",$Creation); 
    $curMonth = date("m");
    $Years = date("y") - $CreationExpand[2]; 
    if($curMonth<$CreationExpand[1] || ($curMonth==$CreationExpand[1] && date("d")<$CreationExpand[0])) 
            $Years--; 

    return $Years;
}

 

Link to comment
Share on other sites

I have 64 bit computer but I failed a y2k38 test returned a date in 1969 lol, guess I'll be finding solution to this. Of course it is using

$date = '2040-02-01';
$format = 'l d F Y H:i';

$mydate1 = strtotime($date);
echo '<p>', date($format, $mydate1), '</p>';

but when I use

$date = '2040-02-01';
$format = 'l j F Y H:i';

$mydate2 = new DateTime($date);
echo '<p>', $mydate2->format($format), '</p>';

I get my expected future date

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.