Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

Working with Dates

Discussion in 'Information Technology' started by Francophone, Jul 28, 2006.

Tags:
  1. Francophone

    Francophone
    Expand Collapse
    Guest

    I need to generate a report which grabs data from the 3 previous months (ie.
    Today is July 18, so I'd want to grab data from April to June).

    Currently I am using the dateserial function and subracting 3 months for my
    start date and DateSerial(year(date()),1,1) as my end date. But I also had
    to include an if clause for Dates where the month is before April where I
    have to set the year back 1 also (ie. Start date =
    DateSerial(year(date))-1,month(date())+9,1).

    Is there a better way to set the start date?

    TIA
     
  2. Loading...

    Similar Threads Forum Date
    Working with Christians #3 Blogs Oct 17, 2015
    Working with Christians #2 Blogs Oct 17, 2015
    Working With Muslims Blogs Oct 17, 2015
    Working with Christians Blogs Oct 17, 2015
    USA Working Mother, Washington Powerhouse? Good Luck. Breaking News Aug 2, 2014

  3. John Vinson

    John Vinson
    Expand Collapse
    Guest

    On Tue, 18 Jul 2006 21:28:01 -0700, Francophone
    <Francophone@discussions.microsoft.com> wrote:

    >I need to generate a report which grabs data from the 3 previous months (ie.
    >Today is July 18, so I'd want to grab data from April to June).
    >
    >Currently I am using the dateserial function and subracting 3 months for my
    >start date and DateSerial(year(date()),1,1) as my end date. But I also had
    >to include an if clause for Dates where the month is before April where I
    >have to set the year back 1 also (ie. Start date =
    >DateSerial(year(date))-1,month(date())+9,1).
    >
    >Is there a better way to set the start date?


    Sure: set both the start and end date in an expression which works any
    time, and doesn't need any IIF:

    >= DateSerial(Year(Date()), Month(Date()) - 4, 1) AND < DateSerial(Year(Date()), Month(Date()), 1)


    will get all of April, May, and June 2006 if run today - and all of
    January 2007, December 2006, and November 2006 if run anytime next
    February. DateSerial happily accepts negative numbers, months
    arguments greater than 12, and day arguments greater than 31 and makes
    the appropriate calculation; e.g.

    ?DateSerial(2006, 13, -365)
    12/31/2005

    ?dateserial(1900, 1200, 300)
    9/25/2000

    John W. Vinson[MVP]
     
  4. Francophone

    Francophone
    Expand Collapse
    Guest

    Thanks, John. Funny thing is I did do it this way the first time but didn't
    realize negative numbers would work.

    "John Vinson" wrote:

    > On Tue, 18 Jul 2006 21:28:01 -0700, Francophone
    > <Francophone@discussions.microsoft.com> wrote:
    >
    > >I need to generate a report which grabs data from the 3 previous months (ie.
    > >Today is July 18, so I'd want to grab data from April to June).
    > >
    > >Currently I am using the dateserial function and subracting 3 months for my
    > >start date and DateSerial(year(date()),1,1) as my end date. But I also had
    > >to include an if clause for Dates where the month is before April where I
    > >have to set the year back 1 also (ie. Start date =
    > >DateSerial(year(date))-1,month(date())+9,1).
    > >
    > >Is there a better way to set the start date?

    >
    > Sure: set both the start and end date in an expression which works any
    > time, and doesn't need any IIF:
    >
    > >= DateSerial(Year(Date()), Month(Date()) - 4, 1) AND < DateSerial(Year(Date()), Month(Date()), 1)

    >
    > will get all of April, May, and June 2006 if run today - and all of
    > January 2007, December 2006, and November 2006 if run anytime next
    > February. DateSerial happily accepts negative numbers, months
    > arguments greater than 12, and day arguments greater than 31 and makes
    > the appropriate calculation; e.g.
    >
    > ?DateSerial(2006, 13, -365)
    > 12/31/2005
    >
    > ?dateserial(1900, 1200, 300)
    > 9/25/2000
    >
    > John W. Vinson[MVP]
    >
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page