Converting separate month, day and year values into a timestamp

Given the variables $year $month $day $hour $minute you can do:

strtotime("$year-$month-$day $hour:$minute");

Be careful to enclose the variables with ", never in this case with '.

UPDATE (thanks to comments of @Clockwork and @Tadeck):

In case there is a variable $timeofday that represents the time of day (i.e. AM or PM), then you can parse it this with:

strtotime("$year-$month-$day $hour:$minute$timeofday");

that is to say, just attach that variable to the end of the text.


why convert string to date when you already know year month and date.

use setDate funtion

<?php
$date = new DateTime();
$date->setDate(2001, 2, 3);
echo $date->format('Y-m-d');
?>