[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Amend date function

Hi,

Below is a date function that i use to test to see whether it is the first working day of the month and if it is i do some other stuff.

Can i have this amended so it checks to see if it is the 2nd day of the working day of the month

Thanks
Seamus

Function IsFirstWorkingDay(dt As Date) As Boolean
    Dim FirstWorkingDay As Date

    FirstWorkingDay = DateSerial(Year(dt), Month(dt), 1)
    Select Case Weekday(FirstWorkingDay, vbMonday)
        Case 6
            FirstWorkingDay = FirstWorkingDay + 2
        Case 7
            FirstWorkingDay = FirstWorkingDay + 1
    End Select
   
    IsFirstWorkingDay = dt = FirstWorkingDay
   
End Function
0
Seamus2626
Asked:
Seamus2626
  • 3
  • 3
1 Solution
 
wshark83Commented:
hi this will do the trick (it now marks the 2nd working day)

Function IsFirstWorkingDay(dt As Date) As Boolean
    Dim FirstWorkingDay As Date

    FirstWorkingDay = DateSerial(Year(dt), Month(dt), 1)
    Select Case Weekday(FirstWorkingDay, vbMonday)
        Case 6
            FirstWorkingDay = FirstWorkingDay + 3
        Case 7
            FirstWorkingDay = FirstWorkingDay + 2
    End Select
   
    IsFirstWorkingDay = dt = FirstWorkingDay
   
End Function
0
 
Rory ArchibaldCommented:
Try
Function IsSecondWorkingDay(dt As Date) As Boolean
    Dim SecondWorkingDay As Date

    SecondWorkingDay = DateSerial(Year(dt), Month(dt), 2)
    Select Case Weekday(SecondWorkingDay , vbMonday)
        Case 6
            FirstWorkSecondWorkingDay = SecondWorkingDay + 2
        Case 7
            SecondWorkingDay = SecondWorkingDay + 1
    End Select
    
    IsSecondWorkingDay = dt = SecondWorkingDay 
    
End Function

Open in new window

0
 
Seamus2626Author Commented:
I have tried to use these but my syntax in the sub is wrong, i am trying

But am getting argument not optional and its pointing to IsSecondWorkingDay

How can i call this function, ask if its true and if it is, do the sub DoMonthEnd

Thanks
Seamus


 If IsSecondWorkingDay = True Then
     
     DoMonthEnd
     
     End If
     
   
End If
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Rory ArchibaldCommented:
You have to pass it a date to check, just as you did the original function. For example, to check today:


 If IsSecondWorkingDay(Date) Then

Open in new window

0
 
Seamus2626Author Commented:
Hey guys, both of your functions bring me into DoMonthEnd today, when i shouldnt be coming in today as it is not the 2nd working day of the month. It is the first working day.

SecondWorkingDay

This equals 02/04/2012 in your code Rory when it should be 03/04/2012

Thanks
Seamus
0
 
Rory ArchibaldCommented:
My bad:
Function IsSecondWorkingDay(dt As Date) As Boolean
    Dim SecondWorkingDay As Date

    SecondWorkingDay = DateSerial(Year(dt), Month(dt), 2)
    Select Case Weekday(SecondWorkingDay, vbMonday)
        Case 1
            SecondWorkingDay = SecondWorkingDay + 1
        Case 6
            SecondWorkingDay = SecondWorkingDay + 2
        Case 7
            SecondWorkingDay = SecondWorkingDay + 3
    End Select
    
    IsSecondWorkingDay = dt = SecondWorkingDay
    
End Function

Open in new window

0
 
Seamus2626Author Commented:
Thats the one, thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now