Results 1 to 9 of 9
  1. #1
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287

    Finding the first Monday of the year

    Hey guys,



    What's the easiest way to get the first Monday of the year that is before Jan 1. For 2014, it would pull 12/30/13.

    So if Jan 1 is not a Monday, go backwards until you hit a Monday?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    That's what I would do. Do you need the procedure?

  3. #3
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Yes, I googled and found something that didn't work too well.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Just a minute and I'll post it.

  5. #5
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Code:
    iif(weekday(dateserial(year(date()),1,1),vbMonday)>1,dateadd("d",1-weekday(dateserial(year(date()),1,1),vbMonday),dateserial(year(date()),1,1)),dateserial(year(date()),1,1))


    See any issues with this? Seems to work for 2013.

    I'm curious if you have a much simpler version.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Put this in a Standard Module:
    Code:
    Public Function FirstMonday(MyYear As Integer) As Date
    '-- Returns the Monday before the 1st of the year
       If Nz(MyYear, 0) = 0 Then
          '-- Year not realistic
          MyYear = Year(Date)
       End If
       Dim ThisDate As Date
       ThisDate = DateSerial(MyYear, 1, 1)
       Do While Weekday(ThisDate, vbSunday) <> 2
          ThisDate = ThisDate - 1
       Loop
       FirstMonday = ThisDateEnd Function

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    I tend to use Public Procedures rather than IIF's as they are easier to document and understand years later by someone else. Just my $0.02.

  8. #8
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Very good point. I'll start switching over Public Functions then.

    Appreciate the help!

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Any time. Glad we could help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dsum data between to dates for this year and last year
    By sdel_nevo in forum Programming
    Replies: 1
    Last Post: 06-13-2013, 06:48 AM
  2. Replies: 4
    Last Post: 01-09-2013, 11:16 AM
  3. Replies: 2
    Last Post: 02-07-2012, 05:39 PM
  4. Replies: 4
    Last Post: 01-10-2012, 06:26 PM
  5. Finding data between two date for any year
    By gemini2 in forum Access
    Replies: 4
    Last Post: 04-05-2006, 06:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums