Search

How to Add Year|Month|Day|Hour|Minutes|Second to Date and Time in PHP?

  • Share this:
post-title

In this tutorial we will go over the demonstration of how to add specific date and time 
(Year,Month,Day,Hour,Minutes,Second) 

I will give you very simple example how to add time to date time in PHP. so let's see both examples with output:

Example 1: PHP Add Year to Date Time

<?php
    $date = '2022-01-18 09:22:34';
    $strtotime = strtotime("+15 Years ",strtotime($date));
    $newDate = date('Y-m-d H:i:s',$strtotime);
  
    echo $newDate;
?>

Output:

2037-01-18 09:22:34

Example 2: PHP Add Month to Date Time

<?php
    $date = '2022-01-18 09:22:34';
    $strtotime = strtotime("+9 months ",strtotime($date));
    $newDate = date('Y-m-d H:i:s',$strtotime);
  
    echo $newDate;
?>

Output:

2022-10-18 09:22:34

Example 3: PHP Add Days to Date Time

<?php
    $date = '2022-01-18 09:22:34';
    $strtotime = strtotime("+9 Days ",strtotime($date));
    $newDate = date('Y-m-d H:i:s',$strtotime);
  
    echo $newDate;
?>

Output:

2022-10-27 09:22:34

Example 4: PHP Add Minutes to Date Time

<?php
    $date = '2022-01-18 09:22:34';
    $strtotime = strtotime("+9 minutes ",strtotime($date));
    $newDate = date('Y-m-d H:i:s',$strtotime);
  
    echo $newDate;
?>

Output:

2022-01-18 09:31:34

Example 5: PHP Add Seconds to Date Time

<?php
    $date = '2022-01-18 09:22:34';
    $strtotime = strtotime("+9 seconds ",strtotime($date));
    $newDate = date('Y-m-d H:i:s',$strtotime);
  
    echo $newDate;
?>

Output:

2022-01-18 09:22:43
About author
Here’s My little description of your attention on Me and My blog. I am here to help you with PHP programming.
View all posts (53)