convert three variable data into a date format in php

Sibin Francis picture Sibin Francis · Feb 13, 2013 · Viewed 8k times · Source

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??

Answer

Ja͢ck picture Ja͢ck · Feb 13, 2013

PHP doesn't really have a date variable type, but it can handle time stamps; such a time stamp can be created with mktime():

$ts = mktime(0, 0, 0, $month, $day, $year);

This can then be used with date() to format it:

$formatted = date('Y-m-d', $ts);