Hi. I am trying to increment a date by one day, that is already set in a variable ($first_date) in this format 2005-04-02

This is the closest I have got so far:

$first_date = $_GET['first_date'];
date ("Y-m-d", strtotime("$first_date, +1 day"))

But this to my dismay resets $first_date to today’s current date!

I’m sure this is an easy task for many of you guys. But for me; it’s driving me bonkers!

Thanks

Ben

    you're extremely close... i think it's your comma that's throwing you off. try this:

    $first_date = '2005-04-02';
    echo date('Y-m-d', strtotime("$first_date +1 day"));
    

    works for me

      Thank you
      I’m sorry but i made a mistake with the last query. Its not working at all for me.
      Even without the comma, the variable $first_date is rendered empty.

      the query i am trying to make work is, but , is incrementing 1 day from today’s date is:

      $first_date = $_GET['first_date'];
      $first_date = date("Y-m-d", strtotime("+1 day"));

      Thanks again

        when you use "$_GET['first_date']", that is implying that in your URL, you have "?first_date=2005-04-02".

        is that the case, or is your URL empty of a query string?

          obsidian wrote:

          when you use "$_GET['first_date']", that is implying that in your URL, you have "?first_date=2005-04-02".

          is that the case, or is your URL empty of a query string?

          yes my URL is empty; "?first_date="

            well, then, you need to come up with an error check to either set a default of today or do something else if the URL is empty... for instance, here's how you'd default to today:

            if (isset($_GET['first_date'])) {
              $first_date = !empty($_GET['first_date']) ? $_GET['first_date'] : date('Y-m-d');
              echo date('Y-m-d', strtotime("$first_date +1 day");
            } else {
              echo "You must choose a date!";
            }
            
              4 years later
              hotliquer;10713047 wrote:

              Thank you
              I’m sorry but i made a mistake with the last query. Its not working at all for me.
              Even without the comma, the variable $first_date is rendered empty.

              the query i am trying to make work is, but , is incrementing 1 day from today’s date is:

              $first_date = $_GET['first_date'];
              $first_date = date("Y-m-d", strtotime("+1 day"));

              Thanks again

              I realise this thread is very old but as it's unanswered if anyone else has this problem ->

              I'm guessing what you are getting there is just a long list of tomorow's date, the reason you get that is you are telling it to add one day onto todays date.

              You will want to use strtotime($first_date, "+1 day");
              which will keep adding 1 day to $first_date rather than keep adding 1 day to today's date!

                Sorry just tested it and it failed thought it worked!

                anyway this is how i got it to work

                $r = 0;
                $i = 0;
                while($r == 0 && $i < 10){
                $graphPlots[$mindate] = 1;
                $mindateTS = strtotime("$mindate +1 day");
                $mindate = date("Y-m-d", $mindateTS);
                //echo $mindate;
                if($mindate == $maxdate){$r = 1;}
                $i++;
                }

                for some reason my server wont process date("Y-m-d", strtotime("$mindate +1 day")); in one go

                  Write a Reply...