Validate the selected date before creating its timestamp. checkdate() can validate the month, day and year before mktime() is called.
$month = 9;
$day = 14;
$year = 2026;
if (checkdate($month, $day, $year)) {
$timestamp = mktime(12, 0, 0, $month, $day, $year);
echo $timestamp;
}This current example appears first; the detailed examples below are retained and modernized for comparison and additional use cases.
We used mktime() function to generate timestamp
| Function | Description |
|---|---|
| mktime() | getting time stamp of input date and time |
| strtotime() | Text string of data to timestamp |
| gettimestamp() | Getting Timestamp from date object |
How Unix timestamp is used to generate Julian Day and Calendar