Extract Day of Week from Date in VBA
Try:
Mydate="14/12/05"
myDay = UCase(Left(WeekdayName(Weekday(Mydate), , 1), 2))
"Tom Ogilvy" wrote:
try this in your code
msgbox format(myDate,"dddd, mmm dd, yyyy")
to see if your date is being interpreted correctly. Try it with an ambigous
date combination like 06/12/05 for Dec 6th.
If it isn't correct, then try converting your date string with cDate
Dim myDate as Date
dim myStr as String
myStr = "06/12/05"
myDate = cDate(myStr)
msgbox format(myDate,"dddd, mmm dd, yyyy")
--
Regards,
Tom Ogilvy
"GLT" wrote in message
...
Hi,
I found the answer in a post that I already posted:
myDay = UCase(Left(WeekdayName(Weekday(myDate)), 2))
One problem I am having is that the above returns the next day (ie. if
myDate = 14/12/05 - which is Wednesday, myDay returns 'TH'.
Anyone have any ideas why this is happening?
"GLT" wrote:
Hi,
I have a msgbox that pops up when the user opens an excel worksheet and
asks
for a specific date in the [dd/mm/yy] forrmat and stores this in a
varible
called myDate.
What I would like to do is extract the first two letters of the day from
this date. So if the date input is 15/12/05, then TH (for Thursday)
would be
returned.
Can anyone help with the VBA to acheive this?
Thanks.
|