Results 1 to 2 of 2

Thread: [02/03] Determine If Invoce Posted > Quarters ago

  1. #1

    Thread Starter
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    [02/03] Determine If Invoce Posted > Quarters ago

    I need to determine if an invoice date was posted more than 2 quarters ago.
    If so, then the account is Inactive

    This is how I did it:
    Code:
            Private Function sSetInactive(ByVal InvoiceDate As Date) As Boolean
                ' return TRUE is older than 2 Quarters, else FALSE
    
                Dim QuarterStart As Date
    
                ' get start date of current quarter
                QuarterStart = DateAdd(DateInterval.Quarter, DateDiff(DateInterval.Quarter, Date.MinValue, Today()), Date.MinValue)
    
                ' get start date 1 quarter ago
                QuarterStart = DateAdd(DateInterval.Quarter, DateDiff(DateInterval.Quarter, Date.MinValue, DateAdd(DateInterval.Day, -1, QuarterStart)), Date.MinValue)
    
                ' get start date 2 quarters ago
                QuarterStart = DateAdd(DateInterval.Quarter, DateDiff(DateInterval.Quarter, Date.MinValue, DateAdd(DateInterval.Day, -1, QuarterStart)), Date.MinValue)
    
                If InvoiceDate < QuarterStart Then
                    Return True
                Else
                    Return False
                End If
    
            End Function
    It seems like a kind of convoluted approach, but it seems to work. Anyone have a more elligant way of doing it?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Determine If Invoce Posted > Quarters ago

    Once you've got the start date of the current quarter you can simply AddMonths(-6) to get the start date two quarters ago. Also, a much more succinct way to do this:
    vb.net Code:
    1. If InvoiceDate < QuarterStart Then
    2.                 Return True
    3.             Else
    4.                 Return False
    5.             End If
    is this:
    vb.net Code:
    1. Return InvoiceDate < QuarterStart
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width