PHP program to convert the days into years, weeks, and days
ADVERTISEMENTS
PHP program to convert the days into years, weeks, and days.
There are you will learn how to convert the days into years, weeks, and days in PHP language.
Base Knowledge:
1Year = 365days
1Week = 7days
Formula:
y = (d / 365)
w = (d % 365) / 7
d = d - ((y * 365) + (w))
Where:
y = year
w = week
d = day
Let us understand this example through the PHP program:
<?php
// PHP program to convert days into years, weeks and days
$d = 464;
$y = NULL;
$w = NULL;
// d = days
// y = years
// w = weeks
// Conversion of days in to years, weeks and days
$y = (int)($d / 365);
$w = (int)(($d % 365) / 7);
$d = (int)($d - (($y * 365) + ($w)));
// Output
echo $y . " Year, " . $w . " Weeks, and " . $d . " Days\n";
?>
Output:
1 Year, 14 Weeks, and 85 Days