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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display value of the date of LAST Sunday?

Status
Not open for further replies.

CTOROCK

Programmer
May 14, 2002
289
US
How can I have the date of the last Sunday shown in a field.
If today's date is 3/26, I would like it to caluculate the date of the most recently past Sunday which would be 3/23.
Can anyone help? Thanks! "The greatest risk, is not taking one."
 
this should do the trick:
=TODAY()-(WEEKDAY(TODAY())-1)
OR, if you have a specific date you want to find the previous sunday for, use
=A1-(WEEKDAY(A1)-1)
where A1 holds the date Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
As a worksheet formula you can use
Code:
  =F3-WEEKDAY(F3)+1
In a macro you can use
Code:
Option Explicit

Sub test()
  MsgBox GetSunday("3/28/03")
End Sub

Function GetSunday(ADate As Date) As Date
  GetSunday = ADate - WeekDay(ADate) + 1
End Function
 
You got different regional settings to me Zathras ???
It's definately -1 for me..... Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
YourDate - WeekDay(YourDate) + 1

where "YourDate" is your date.

?#3/26/2003# - weekday(#3/26/2003#) + 1
3/23/03
 
Rob - nail...head....hit
then
my head.....wall....hit :)

[hammer] Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Thanks a lot guys,
=TODAY()-(WEEKDAY(TODAY())-1)

did it!!!
"The greatest risk, is not taking one."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top