Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 728
Sibin Francis Avatar asked May 16 '26 21:05

Sibin Francis


2 Answers

Another way to handle this is to utilize DateTime class

$date = new DateTime($year.'-'.$month.'-'.$day);
echo $date->format('Y-m-d');
like image 57
peterm Avatar answered May 19 '26 15:05

peterm


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);
like image 40
Ja͢ck Avatar answered May 19 '26 15:05

Ja͢ck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!