Same day last year problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rjfjohnson@hotmail.com

    Same day last year problem

    Hey,

    Today is Thursday 16-Feb-06. The same thursday last year is 17-Feb-05.
    Because I am comparing daily sales between years, I need to know the
    date of the same weekdayname as last year, so that I am comparing
    Saturdays with Saturdays, Sundays with Sundays, etc

    ie, 16-feb-06 goes to 17-feb-05
    28-july-06 goes to 27-july-05 and so on

    I have tried all sorts of dateadd('2004-01-01'............ . etc, and I
    am all out of ideas.

    Any suggestions would be very much appreciated.

    Thanks
    Ryan

  • NC

    #2
    Re: Same day last year problem

    rjfjohn...@hotm ail.com wrote:[color=blue]
    >
    > Today is Thursday 16-Feb-06. The same thursday last year is 17-Feb-05.
    > Because I am comparing daily sales between years, I need to know the
    > date of the same weekdayname as last year, so that I am comparing
    > Saturdays with Saturdays, Sundays with Sundays, etc[/color]

    Essentially, you need to know the date that was 52 weeks before today:

    $today = time();
    $year_ago = $today - 52*7*24*60*60;
    $today_date = date('Y-m-d', $today);
    $year_ago_date = date('Y-m-d', $year_ago);

    Now you can use $today_date and $year_ago_date in a query...

    Cheers,
    NC

    Comment

    • rjfjohnson@hotmail.com

      #3
      Re: Same day last year problem

      Thank you so much,

      You have saved me so much time, I think im an idiot

      Comment

      • rjfjohnson@hotmail.com

        #4
        Re: Same day last year problem

        NC,

        I tried that function - it works rather well except, it doesnt seem to
        take into account leap years.

        Who in their right mind would invent a leap year!!!???

        Any suggestions to jump over this hurdle?

        Ryan

        Comment

        • d

          #5
          Re: Same day last year problem

          <rjfjohnson@hot mail.com> wrote in message
          news:1140066115 .796988.54290@g 43g2000cwa.goog legroups.com...[color=blue]
          > NC,
          >
          > I tried that function - it works rather well except, it doesnt seem to
          > take into account leap years.
          >
          > Who in their right mind would invent a leap year!!!???
          >
          > Any suggestions to jump over this hurdle?[/color]

          Try:

          $d=strtotime("-1 year");

          dave
          [color=blue]
          > Ryan
          >[/color]


          Comment

          • Kimmo Laine

            #6
            Re: Same day last year problem

            <rjfjohnson@hot mail.com> wrote in message
            news:1140066115 .796988.54290@g 43g2000cwa.goog legroups.com...[color=blue]
            > NC,
            >
            > I tried that function - it works rather well except, it doesnt seem to
            > take into account leap years.
            >
            > Who in their right mind would invent a leap year!!!???
            >[/color]


            Blame the solar system! :-)



            --
            "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
            spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)


            Comment

            • rjfjohnson@hotmail.com

              #7
              Re: Same day last year problem

              Personally I beleive that there should be 10 days per week, 10 weeks
              per month and 10 months per year, with 10 hours per day, 100 minutes
              per hour, 100 seconds per minute, and we should just suffer with out of
              phase moons, etc.

              Besides, its not like we need the stars for navigation any more

              Comment

              • Jerry Stuckle

                #8
                Re: Same day last year problem

                rjfjohnson@hotm ail.com wrote:[color=blue]
                > NC,
                >
                > I tried that function - it works rather well except, it doesnt seem to
                > take into account leap years.
                >
                > Who in their right mind would invent a leap year!!!???
                >
                > Any suggestions to jump over this hurdle?
                >
                > Ryan
                >[/color]

                Ryan,

                I'm confused. NC's code works fine. Extrapolating it for several years
                (and formatting to get the day of the week), I get:

                Today is Thursday, February 16, 2006
                1 years ago was Thursday, February 17, 2005
                2 years ago was Thursday, February 19, 2004
                3 years ago was Thursday, February 20, 2003
                4 years ago was Thursday, February 21, 2002
                5 years ago was Thursday, February 22, 2001
                6 years ago was Thursday, February 24, 2000
                7 years ago was Thursday, February 25, 1999
                8 years ago was Thursday, February 26, 1998
                9 years ago was Thursday, February 27, 1997
                10 years ago was Thursday, February 29, 1996

                This is fine for the last few years, but eventually (when you get seven
                extra days, Year 2000 in this example) it's off a week.
                But for the last 3-4 years it should be fine.

                What is different about what you're looking for?

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • rjfjohnson@hotmail.com

                  #9
                  Re: Same day last year problem

                  Jerry, NC,

                  You are right. I didn't copy it correctly.

                  Thanks again,
                  Ryan

                  Comment

                  • Tim Roberts

                    #10
                    Re: Same day last year problem

                    rjfjohnson@hotm ail.com wrote:
                    [color=blue]
                    >Personally I beleive that there should be 10 days per week, 10 weeks
                    >per month and 10 months per year, with 10 hours per day, 100 minutes
                    >per hour, 100 seconds per minute, and we should just suffer with out of
                    >phase moons, etc.[/color]

                    The French actually tried almost that exact system shortly after the French
                    Revolution, when they were trying to shed all remnants of the "old ways".



                    It did not have happy results. Workers objected to having their weekly day
                    off of work come once every 10 days instead of once every 7...
                    --
                    - Tim Roberts, timr@probo.com
                    Providenza & Boekelheide, Inc.

                    Comment

                    Working...