Hey guys, thanks for taking the time to read this.

I've coded PHP for quite a while however it's been roughly 2 years now since i've really and truly had to use these skills. I'm in the preliminary stages of writing a quick script that counts a number of days from a certain date. The calendar script i'm actually working with is one from Sam's teach yourself PHP in 24 hours: http://www.deadlysinx.net/FREE/CALENDAR/calendar.php

Source: http://www.deadlysinx.net/FREE/CALENDAR/calendar.phps.txt

Essentially, the calendar script is complete. Let's say today's date is October 5th, 2012 and I want to know the date 45 days away from today. How can I add 45 days to $thisDay and make it show the proper date? I've tried a number of things w/no success yet. Then again i'm just really getting started and wishing I would have kept up w/PHP over the years!

I'm not looking for someone to do the coding for me just point me in the right direction and I'd appreciate the help!

Thanks,

D.S.X

    If $thisDay is a UNIX timestamp integer, then you can simply do:

    $futureTime = strtotime("+45 days", $thisDay);
    

    If $thisDay is a string representation of a date/time, then you could convert it with the same function:

    $futureTime = strtotime("+45 days", strtotime($thisDay));
    

      Heya NogDog,

      Thanks a million for the reply.

      I guess I failed to mention that

      $thisDay = date("d");

      So it's likely the strtotime() function is what i'm looking for. Thanks mate!

        DeadlySin3;11014597 wrote:

        Heya NogDog,

        Thanks a million for the reply.

        I guess I failed to mention that

        $thisDay = date("d");

        So it's likely the strtotime() function is what i'm looking for. Thanks mate!

        Actually, probably not. "06", say, doesn't look like much of anything that strtotime can work with (should "06" plus forty-five days be "20" or "21"? It depends on the month. That of course is assuming that "06" is a day and not an hour, minute, second, or a reference to June or 2006).

        If you want strtotime to count 45 days from the current time then strtotime('+45 days') would be sufficient.

          Weedpacket;11014607 wrote:

          Actually, probably not. "06", say, doesn't look like much of anything that strtotime can work with (should "06" plus forty-five days be "20" or "21"? It depends on the month. That of course is assuming that "06" is a day and not an hour, minute, second, or a reference to June or 2006).

          If you want strtotime to count 45 days from the current time then strtotime('+45 days') would be sufficient.

          Thanks for the reply, Weedpacket.

          I do want to count 45 days (or X amout of days entered within a form) ahead of a certain date. Not necessarily todays date. Even count back from future dates.

          The main purpose behind this script is : at work, I find i'm constantly looking at a calendar and counting days for customers. I would like to just enter in a certain date.. let's say for example their account will be eligible for a special offer on January 15, 2013. I can do an over-ride 45 days BEFORE this date to make them eligible December 1. Instead of looking at the calendar and counting days, I would like to just input the date into the calendar and click so it'll show me X amount of days from X date or even add days to a certain date.

          I know i'm going to have to re-work how i'm adding the days. I get the feeling that this SHOULD be a simple process but i'm overcomplicating things.

          Again I want to re-iterate that I haven't coded in years lol. Things are slowly but surely coming back to me but it's taking longer than I would have liked. 5 years ago I could have had the code I wanted to use mapped out in my head before I got home from work and slapped in into gphpEdit and been done!

            Well, as long as you can get the certain date into a Unix timestamp, you can use it as a second argument to strtotime.

            How you get it there depends on what format it's currently in; if it's a Unix timestamp already, you're already done of course; if it's coming from a database, the DBMS probably has functions to do the job (in fact, the DBMS probably has functions allowing you to add the 45 days as well); if it's any unambiguous string format (see [man]datetime.formats.date[/man]) then you can (re)use strtotime; if it's a bunch of numbers representing day, month, and year, then [man]mktime[/man] can assemble them into a timestamp (and you can also choose to add the 45 days at this point as well).

              Thanks again Weedpacket for the info's.

              So, I've decided to completely re-think what it is i'm trying to do. To simplify the situation, I removed the calendar altogether. (for now)
              I've got some basic code that does what i'm looking to do. Easily see a date x amount of days from a certain date.

              Anyway, here's what i've come up with so far and it works like a charm.

              <?php
              
              ### Can use "day" "week" "month" or "year"
              
              $date = "2012-10-06";
              $newDate = strtotime ( '-45 day' , strtotime ( $date ) ) ;
              $newDate = date ( 'Y-m-j' , $newDate );
              
              echo $newDate;
              ?>
              

              I found this to be almost too simple to work effectively but i'll be darned if it doesn't. Hope it helps someone else out there!

                And all you need to do now is work out how to build up a string like "2012-10-06" from what your calendar widget supplies (assuming you can't do that in the widget itself) and you're done!

                  Pretty much! It won't be entirely too tough to figure this; My issue now is time. I have mandatory O.T until Monday so i'll be working (entirely too hard) for the next few days! I really appreciate all of the help here!

                    So pretty much, thanks to the pointers in the correct direction from the kind folks here on this forum I was able to completely get done what I wanted to w/this script.

                    After getting that last snippet to actually do the date subtraction I was looking to get done - I just linked each day of the month to a pop up window that displays the information i'm looking for.
                    Then I put up a bg image and slapped a really quick style sheet together to make it look not so bare-bones and voila! Thanks again Nogdog & Weedpacket!

                    If you're interested in seeing it in action, I put it up online here: http://deadlysinx.net/FREE/cal.upgrade.chk/pub.calendar.php

                    Source Code: [ Highlighted for PHP ]
                    http://deadlysinx.net/FREE/cal.upgrade.chk/pub.calendar.src.html
                    Source Code: [ Highlighted for PHP ] for the pop up window:
                    http://deadlysinx.net/FREE/cal.upgrade.chk/inc/pub.pop_view.src.html

                      Write a Reply...