PDA

View Full Version : date falls on monday display the date of saturday



Kaniguan1969
02-15-2014, 06:08 AM
Hi guys,

I have a requirement if the date falls on monday i need to show/get the date of saturday using excel vba. thanks in advance.

ex. feb10, get the date 02-08

GarysStudent
02-15-2014, 06:31 AM
Perhaps:


Public Function ModDate(d As Date) As Date
ModDate = d
If Format(d, "dddd") = "Monday" Then
ModDate = ModDate - 2
End If
End Function

p45cal
02-15-2014, 10:17 PM
An alternative, since your location is showing as the Phillipines where your locale settings may use different day of the week strings:
Public Function ModDate(d As Date) As Date
ModDate = d
If Weekday(d) = 2 Then ModDate = d - 2
End Function

westconn1
02-15-2014, 10:18 PM
as the above depends on english locale settings, better like

d = Date
If Weekday(d) = vbMonday Then d = d - 2


edit: too slow

Kaniguan1969
02-16-2014, 04:36 AM
Thank you guys for the reply. Well let you know the results tomorrow. thanks.