Solved

Amend date function

Posted on 2012-04-02
7
252 Views
Last Modified: 2012-04-02
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
Comment
Question by:Seamus2626
  • 3
  • 3
7 Comments
 
LVL 6

Expert Comment

by:wshark83
ID: 37796321
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
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37796342
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
 

Author Comment

by:Seamus2626
ID: 37796398
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37796421
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
 

Author Comment

by:Seamus2626
ID: 37796536
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
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 37796586
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
 

Author Closing Comment

by:Seamus2626
ID: 37796631
Thats the one, thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now