Results 1 to 2 of 2
  1. #1
    RachelBedi is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Jul 2012
    Posts
    67

    Find the Nearest Previous Saturday

    Good Afternoon!

    I need to write a query which pulls a date range, I don't want to write a between [enter start date] and [enter end date] - I want to write one query that doesn't need to be manipulated too much that will take a date range between [nearest previous saturday] and Date()

    I hope that makes sense, if someone can give me a super simple solution that would be great :-D



    Thank you!

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Here's a small procedure that may help.
    Code:
    Function NearestSaturday(Optional myDate As Date)
        Dim i As Integer
        If myDate = #12:00:00 AM# Then myDate = Date
        For i = 0 To 7
            If Weekday(myDate - i) = 7 Then
            Debug.Print "Requested Date is " & WeekdayName(Weekday(myDate)) & "  " & myDate
            Debug.Print "Previous " & WeekdayName(Weekday(myDate - i)) & " " & myDate - i
            End If
        Next i
    End Function
    You can submit a valid Date and the routine will tell you the Requested Day and Date and will tell you the Date of the previous Saturday.

    Here is small test routine
    Code:
    Sub testNearestSaturday()
    Debug.Print NearestSaturday(#4/23/1953#)
    End Sub
    and here is the result

    Requested Date is Thursday 23/04/1953
    Previous Saturday 18/04/1953
    Hope it's useful to you
    Last edited by orange; 09-21-2012 at 02:07 PM. Reason: code tags

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

Similar Threads

  1. Round up to nearest nickel
    By Rhubie in forum Access
    Replies: 15
    Last Post: 09-07-2012, 06:50 AM
  2. Count Sunday & Saturday between two days.
    By kashif.special2005 in forum Queries
    Replies: 2
    Last Post: 02-23-2012, 06:19 PM
  3. Last of Previous record
    By leonhuynh2006 in forum Queries
    Replies: 4
    Last Post: 10-15-2011, 04:31 PM
  4. Previous record
    By leonhuynh2006 in forum Forms
    Replies: 1
    Last Post: 10-06-2011, 06:41 AM
  5. Previous value
    By yegnal in forum Forms
    Replies: 0
    Last Post: 07-22-2007, 07:51 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