Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Matters 2

Status
Not open for further replies.

dhaveedh

Programmer
Aug 13, 2003
112
GB
Can anyone tell me what is wrong with this?

I am trying to get the date of Last sunday


Function getLastSunday()

Dim dDate As String

dDate = Format(Date, "dddd")

Do Until Format(dDate, "dddd") = "Sunday"

dDate = Date - 1

Loop

getLastSunday = dDate

End Function

Help appreciated

KISS - Keep It Simple Sugar!
 
Hi,
Code:
Function getLastSunday()

    Dim dDate As Date
    
    dDate = Now
    
    Do Until Format(dDate, "dddd") = "Sunday"
    
    dDate = dDate - 1
     
    Loop
        
    getLastSunday = dDate
    
End Function
:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
You have set "dDate" as a string but you are attempting to compute "dDate = Date - 1" which is a numeric value.

Or ... in one line
[tt]
getLastSunday = DateAdd ("d", -(WeekDay(Date())-vbSunday), Date())
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top