Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to increase or decrease dates in the given dates

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 113
    Comment on it

    Hello Reader's if you have the current date and you want to get some past dates or future dates then here you can see it. PHP offers you to use inbuilt function strtotime. Lets see how you can adjust the dates with this. Here you will get the next date of current date

      <?php          
            $stop_date = date('Y-m-d H:i:s', strtotime("2015-12-30 15:21:10"));
    
            echo 'date before day adding: '.$stop_date; 
    
            $stop_date = date('Y-m-d H:i:s', strtotime('+1 day', $stop_date));
    
            echo '  Incremented date: '.$stop_date;
        ?>
    

    Output:-

    2015-12-31 15:21:10
    

    Now see if you want to get the past date

    <?php          
                $stop_date = date('Y-m-d H:i:s', strtotime("2015-12-30 15:21:10"));
    
                echo 'date before day adding: '.$stop_date; 
    
                $stop_date = date('Y-m-d H:i:s', strtotime('-1 day', $stop_date));
    
                echo '  Incremented date: '.$stop_date;
            ?>
    

    Output:-

    2015-12-29 15:21:10
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: