• We just launched and are currently in beta. Join us as we build and grow the community.

Add Day In Current Date Using PHP

Alucard2k21

Save Scummer
A Rep
0
0
0
Rep
0
A Vouches
0
0
0
Vouches
0
Posts
166
Likes
171
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
In this article we will try to create a Add Day In Current Date using PHP. The code will dynamically add an additional day to current date when you enter some value and submitted. This is a user-friendly kind of program feel free to modify it. To learn more about this tutorial, just follow the step below.

Getting Started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.

And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" name="viewport" content="width=device-widht, initial-scale=1"/>
  5. <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  6. </head>
  7. <body>
  8. <nav class="navbar navbar-default">
  9. <div class="container-fluid">
  10. <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
  11. </div>
  12. </nav>
  13. <div class="col-md-3"></div>
  14. <div class="col-md-6 well">
  15. <h3 class="text-primary">Add Day In Current Date Using PHP</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <div class="col-md-8">
  18. <?php
  19. date_default_timezone_set

    (

    "Etc/GMT-8"

    )

    ;
  20. $date

    =

    date

    (

    "M d, Y h:i:s A"

    )

    ;
  21. echo

    "<h4>Today Time: <span class='text-success'>"

    .

    $date

    .

    "</span></h4>"

    ;
  22. ?>
  23. <?php

    include

    'add.php'

    ?>
  24. </div>
  25. <div class="col-md-4">
  26. <form action="" method="POST">
  27. <label>Enter a value</label>
  28. <div class="form-group">
  29. <input type="number" class="form-control" min="0" name="num">
  30. </div>
  31. <center><button class="btn btn-primary" name="add">Add</button></center>
  32. </form>
  33. </div>
  34. </div>
  35. </body>
  36. </html>

Creating the Main Function

This code contains the main function of the application. This code will add extra day when you submit some value. To make this just copy and write these block of codes below inside the text editor, then save it as add.php
  1. <?php
  2. if

    (

    isset

    (

    $_POST

    [

    'add'

    ]

    )

    )

    {
  3. $num

    =

    $_POST

    [

    'num'

    ]

    ;
  4. $str

    =

    "days"

    ;
  5. echo

    "<h5>Added <strong><span class='text-danger'>"

    .

    $num

    .

    "</span></strong> "

    .

    $str

    .

    ".</h5>"

    ;
  6. $newdate

    =

    date

    (

    'M d, Y h:i:s A'

    ,

    strtotime

    (

    "+$num

    $str

    "

    ,

    strtotime

    (

    $date

    )

    )

    )

    ;
  7. echo

    "<h4> Your New Time: <span class='text-primary'>"

    .

    $newdate

    .

    "</span></h4>"

    ;
  8. }

  9. ?>

There you have it we successfully created Add Day In Current Date using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!


Download
You must upgrade your account or reply in the thread to view hidden text.
 

442,401

317,942

317,951

Top