I have a string '2019-01-05', I need to convert this to a date I assume so I can add an subtract a day from it. I then need to get the month, day and year from it.

        $Today = strtotime($StringDate);
        $Yesterday = strtotime('-1 day', strtotime($Today));
        $Tomorrow = strtotime('+1 day', strtotime($Today));

I need to echo date('m', $Tomorrow) for example but I'm getting all sorts of errors.

Where am I going wrong?

    You're not saying what sorts of errors you're getting. But I will point out that you're using strtotime to get $Today and putting the result straight back into strtotime. Generally, you're using the function about twice as much as you need to.

      Just because it's not quite bedtime yet...it sounds like you're trying to do something like this?

      22:37 $ php -a
      Interactive shell
      
      php > ini_set('date.timezone', 'America/New_York');
      php > $today = '2019-05-05';
      php > $tomorrow = date('Y-m-d', strtotime('+1 day', strtotime($today)));
      php > echo $tomorrow;
      2019-05-06
      

      ...or...

      $Tomorrow = date('Y-m-d', strtotime("$StringDate tomorrow"));

      Or even:

      $tomorrow = new \DateTime( 'tomorrow', new \DateTimeZone('America/New_York') );

      With some parenthesis you can chain a format() call directly on that if you want to immediately output it to the screen and not bother keeping the variable around.

        Write a Reply...