phpalgorithmtimedata-conversionphrase

Convert number of days to English phrase expressing weeks and days


I have a number of days to a date in the future but would like to know how many weeks and days it is. Also, noting that if its less than a week, then it simply returns the same number.

Is this possible?

e.g. 17 days would be 2 weeks and 3 days

e.g. 4 days would be 4 days


Solution

  • I would try something like this:

    $days = 17;
    $weeks = floor($days / 7);
    $dayRemainder = $days % 7;
    echo $days.'<br/>'.$weeks.'<br/>'.$dayRemainder;//add whatever logic you need here to get the display the way you want it.