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??
Another way to handle this is to utilize DateTime class
$date = new DateTime($year.'-'.$month.'-'.$day);
echo $date->format('Y-m-d');
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With