strtotime() parses English date/time text and returns a Unix timestamp or false on failure. Always test the return value before formatting it.
$timestamp = strtotime('next Monday 10:30');
if ($timestamp === false) {
echo 'Invalid date/time expression';
} else {
echo date('Y-m-d H:i:s', $timestamp);
}For user-entered dates with a known format, createFromFormat() gives you tighter control than free-form parsing.
echo strtotime('now'); Output is here 1790726429$dt1='25-12-2015'; // First Date one in a variable
$dt2='01-07-2016'; // Second Date in a variable
$dt11=strtotime($dt1); // Converting first date to timestamp
$dt22=strtotime($dt2); // Converting second date to timestamp
if($dt11 > $dt22){
$dt=$dt1;
}else{
$dt=$dt2;
}
echo "Highest Date : $dt ";
Output is here
Highest Date : 01-07-2016
What is the weekday today ?
echo date('D',strtotime('now'))
$pub_date='2024-02-11T15:36:25Z'
$my_date=date('d-M-Y h:i:s', strtotime($pub_date));
| Code | Output |
| date('m-d-Y',strtotime('now')) | 09-30-2026 |
| date('m-d-Y',strtotime('11 July 2016')) | 07-11-2016 |
| date('m-d-Y',strtotime('+1 day')) | 10-01-2026 |
| date('m-d-Y',strtotime('+1 week')) | 10-07-2026 |
| date('m-d-Y',strtotime('+1 month')) | 10-30-2026 |
| date('m-d-Y',strtotime('+1 month 3 days')) | 11-02-2026 |
| date('m-d-Y',strtotime('+2 months -1 day')) | 11-29-2026 |
| date('m-d-Y',strtotime('Wednesday')) | 09-30-2026 |
| date('m-d-Y',strtotime('Sunday +1 day')) | 10-05-2026 |
| date('m-d-Y',strtotime('first day of this month')) | 09-01-2026 |
| date('m-d-Y',strtotime('last day of this month')) | 09-30-2026 |
| date('m-d-Y',strtotime('first day of next month')) | 10-01-2026 |
| date('m-d-Y',strtotime('last day of next month')) | 10-31-2026 |
| date('m-d-Y',strtotime('first day of previous month')) | 08-01-2026 |
| date('m-d-Y',strtotime('last day of previous month')) | 08-31-2026 |
| date('m-d-Y',strtotime('+5 years ')) | 09-30-2031 |
| With Date & Time | |
| date('m-d-Y H:i:s',strtotime('+1 hour ')) | 09-30-2026 06:30:29 |
| date('m-d-Y H:i:s',strtotime('+10 minutes ')) | 09-30-2026 05:40:29 |
| date('m-d-Y H:i:s',strtotime('+20 seconds ')) | 09-30-2026 05:30:49 |
| date('m-d-Y',strtotime('last day of next month +1 Hour')) | 10-31-2026 : 06 |
| date('m-d-Y',strtotime('first day of next month +1 Hour 20 minutes')) | 10-01-2026 : 06 : 50 : 29 |
| Fixed Date | |
| date('m-d-Y',strtotime('25-12-2012 +5 years ')) | 12-25-2017 |
| date('m-d-Y',strtotime('25-12-2012 +1 month 1 week ')) | 02-01-2013 |
| date('m-d-Y',strtotime('12-06-2018 next Monday ')) | 06-18-2018 |
| date('d-M-Y',strtotime('07-06-2018 next Wednesday')) | 13-Jun-2018 |
| Function | Description |
|---|---|
| mktime() | getting time stamp of input date and time |
| gettimestamp() | Getting Timestamp from date object |
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.