1

How could I decrement the date in the text box by 1 day? The value of the dateschedule is 2016-04-02. The output should be 2016-04-01 because I want to decrement it by 1 day. I tried this code:

 if(isset($_REQUEST["submit"]))
        {
        $dateschedule=security($_POST["dateschedule"]);
    echo    $new_time4 = date($dateschedule, strtotime('-1 day'));
        }
Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49

2 Answers2

0

the format of your date function is not going to work as you expect.. see php date manual

and as also posted on another SO question, you may use this:

$new_time4 = date('Y-m-d',(strtotime( '-1 day' , strtotime( $_POST["dateschedule"]))));
Community
  • 1
  • 1
catzilla
  • 1,901
  • 18
  • 31
0

You can also achieve this by using DateTime.

$date = new DateTime('2016-04-02');
$date->modify('-1 day');
echo $date->format('Y-m-d');

//Output: 2016-04-01

https://3v4l.org/mD2GR

I find this alot more readable, you can easily see what you are doing and you can change your output easily with the format funciton.

Jordy
  • 948
  • 2
  • 9
  • 28