Search code examples
phpdatedate-conversion

convert three variable data into a date format in php


i have three variables containing values shown below

                       $day=13
                       $month=2
                       $year=2013

i want to convert these three variable data into a date format in php and store in anoother variable Ho to do this??


Solution

  • Another way to handle this is to utilize DateTime class

    $date = new DateTime($year.'-'.$month.'-'.$day);
    echo $date->format('Y-m-d');