?
Solved

Find the date of this week's Sunday

Posted on 2008-10-16
2
Medium Priority
?
453 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
[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
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1000 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 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 1000 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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

762 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