Solved

Amend date function

Posted on 2012-04-02
7
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
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 …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

726 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