Solved

Amend date function

Posted on 2012-04-02
7
253 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

930 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

9 Experts available now in Live!

Get 1:1 Help Now