\r\n\r\n
Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Need isPayDay Function


\r\n \r\n
 
 
Thread Tools Display Modes

\r\n\r\n\r\n
I need a function that would return true if the date provided was a payday or date of next few weeks paydays.
\r\n
\r\nPaydays are every 14 days on a Friday (not twice a month).
\r\n
\r\nI tried several attempts, but don\'t have a clue where to start, except that the function needs a reference date to calculate from. This is what I have so far, but again, I do not know what I am doing.
\r\n
\r\nCan someone please help ?
\r\n
\r\n
\r\n
Code:
\r\n
    \' PayDay is defined as every 14 days from a fixed date of last know payday.\r\n    Public Function isPayDay(ByVal RefDate As Date, ByVal dDate As Date) As Date\r\n        Dim testDate As Date\r\n        Dim iDay As Integer\r\n        Dim iMonth As Integer\r\n        Dim iYear As Integer\r\n        Dim dayCounter As Integer = 14\r\n        Dim weekCounter As Integer\r\n\r\n        RefDate = DateSerial(2011, November, 4)\r\n\r\n        iDay = Day(dDate)\r\n        iMonth = Month(dDate)\r\n        iYear = Year(dDate)\r\n\r\n        RefDate = DateSerial(2011, November, 4)             \' Starting Reference payday\r\n        dDate = DateSerial(iYear, iMonth, iDay)\r\n\r\n        For weekCounter = 1 To 51 Step 2                     \' 26 paydays in a year.\r\n            testDate = DateAdd("d", dayCounter, RefDate)    \' Add dayCounter to Reference day\r\n            dayCounter += 14                                \' Add multiples of 14 to dayCounter\r\n        Next\r\n\r\n        isPayDay = testDate\r\n\r\n    End Function
\r\n
Thanks in Advance.
\r\n \r\n\r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n'; pd[1388188] = '\r\n\r\n \r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n
\r\n
\r\n  \r\n #2  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 11-21-2011, 09:40 AM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n lpitman\r\n lpitman is offline\r\n\r\n\r\n
Prev Previous Post   Next Post Next
  #1  
Old 11-21-2011, 09:25 AM
lpitman lpitman is offline
Freshman
 
Join Date: Aug 2004
Location: Colorado Springs, Co
Posts: 27
Default Need isPayDay Function


I need a function that would return true if the date provided was a payday or date of next few weeks paydays.

Paydays are every 14 days on a Friday (not twice a month).

I tried several attempts, but don't have a clue where to start, except that the function needs a reference date to calculate from. This is what I have so far, but again, I do not know what I am doing.

Can someone please help ?

Code:
    ' PayDay is defined as every 14 days from a fixed date of last know payday.
    Public Function isPayDay(ByVal RefDate As Date, ByVal dDate As Date) As Date
        Dim testDate As Date
        Dim iDay As Integer
        Dim iMonth As Integer
        Dim iYear As Integer
        Dim dayCounter As Integer = 14
        Dim weekCounter As Integer

        RefDate = DateSerial(2011, November, 4)

        iDay = Day(dDate)
        iMonth = Month(dDate)
        iYear = Year(dDate)

        RefDate = DateSerial(2011, November, 4)             ' Starting Reference payday
        dDate = DateSerial(iYear, iMonth, iDay)

        For weekCounter = 1 To 51 Step 2                     ' 26 paydays in a year.
            testDate = DateAdd("d", dayCounter, RefDate)    ' Add dayCounter to Reference day
            dayCounter += 14                                ' Add multiples of 14 to dayCounter
        Next

        isPayDay = testDate

    End Function
Thanks in Advance.
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->