Solved

Find the date of this week's Sunday

Posted on 2008-10-16
2
408 Views
Last Modified: 2013-11-27
I am trying to find the date of this week's Sunday.  I know this is the first day of the week but i dont know how to find that date programmitcally.   So for instance.. today is thursday 9/16/2008.  I want this field to show sunday october 9/12/2008 till next week when i would want it to show 9/19/2008
0
Comment
Question by:brandonjel
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 22735512
you  can use a function to do that, place this codes in a regular module

Function GetSundayDate(CurrentDate) As Date
   If VarType(CurrentDate) <> 7 Then

        GetSundayDate = Null
   Else

    Select Case Weekday(CurrentDate)
        Case 1
            GetSundayDate = CurrentDate
        Case Else
            GetSundayDate = DateAdd("d", -Weekday(CurrentDate) + 1, CurrentDate)
    End Select
   End If
   
End Function
1
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 250 total points
ID: 22735755
Hello brandonjel,

No need for a UDF; native functions can get it readily.

SELECT SomeDate, DateValue(Format(SomeDate, "d mmm yyyy")) - Weekday(SomeDate) + 1 AS SundayDate
FROM SomeTable

Regards,

Patrick
1

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

744 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

8 Experts available now in Live!

Get 1:1 Help Now