Search code examples
phpdatedate-conversion

Convert days and years to day month and year format in php


So I have the number of days and the year in the following format:

322 days
2009 year

I need to convert this to 2009-11-18

Is there a function in php to achieve this?


Solution

  • Sure, use mktime and date:

    $days = 322;
    $year = 2009;
    echo date('Y-m-d', mktime( 0, 0, 0, 1, $days, $year));
    

    Output: 2009-11-18