Skip to content

spinzar/afghan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

afghan

To convert days, months, and years between the Afghan and Gregorian calendars for the purpose of finding people's age, you can follow these steps:

Create a function called convertDaysToYears. This function will convert a number of days to a number of years, taking into account the different lengths of the Afghan and Gregorian calendars.

Create a function called convertMonthsToYears. This function will convert a number of months to a number of years, taking into account the different lengths of the Afghan and Gregorian calendars.

Create a function called convertYearsToDays. This function will convert a number of years to a number of days, taking into account the different lengths of the Afghan and Gregorian calendars.

Create a function called convertYearsToMonths. This function will convert a number of years to a number of months, taking into account the different lengths of the Afghan and Gregorian calendars.

Create a function called calculateAgeInAfghanYears. This function will calculate a person's age in Afghan years, given their birth date and the current date.

Create a function called calculateAgeInGregorianYears. This function will calculate a person's age in Gregorian years, given their birth date and the current date.

Here is some sample code for these functions:

PHP
function convertDaysToYears($days, $calendar)
{
    $years = 0;
    if ($calendar === 'afghan') {
        $years = $days / 365.25;
    } elseif ($calendar === 'gregorian') {
        $years = $days / 365.2422;
    }

    return $years;
}

function convertMonthsToYears($months, $calendar)
{
    $years = 0;
    if ($calendar === 'afghan') {
        $years = $months / 12;
    } elseif ($calendar === 'gregorian') {
        $years = $months / 12;
    }

    return $years;
}

function convertYearsToDays($years, $calendar)
{
    $days = 0;
    if ($calendar === 'afghan') {
        $days = $years * 365.25;
    } elseif ($calendar === 'gregorian') {
        $days = $years * 365.2422;
    }

    return $days;
}

function convertYearsToMonths($years, $calendar)
{
    $months = 0;
    if ($calendar === 'afghan') {
        $months = $years * 12;
    } elseif ($calendar === 'gregorian') {
        $months = $years * 12;
    }

    return $months;
}

function calculateAgeInAfghanYears($birthDate, $currentDate)
{
    $ageInDays = convertDaysToYears(convertYearsToDays($currentDate) - convertYearsToDays($birthDate), 'afghan');
    $ageInYears = convertDaysToYears($ageInDays, 'afghan');

    return $ageInYears;
}

function calculateAgeInGregorianYears($birthDate, $currentDate)
{
    $ageInDays = convertDaysToYears(convertYearsToDays($currentDate) - convertYearsToDays($birthDate), 'gregorian');
    $ageInYears = convertDaysToYears($ageInDays, 'gregorian');

    return $ageInYears;
}
Use code with caution. Learn more
To use these functions, you can simply pass in the necessary parameters and the function will return the desired result. For example, to calculate a person's age in Afghan years, you would use the following code:

PHP
$birthDate = '1980-03-21';
$currentDate = '2023-09-25';

$ageInAfghanYears = calculateAgeInAfghanYears($birthDate, $currentDate);

echo $ageInAfghanYears; // 43
Use code with caution. Learn more
You can also use these functions to convert days, months, and years between the Afghan and Gregorian calendars for other purposes, such as calculating the date of a future event or the number of days between two dates.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published