Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

excel vba - How to get the Day Name of Date?

I have a small code that gets the Day Name of the Dates listed in Excel. But the problem is, it's not getting the right Day Name(e.g. Tuesday).

For Example:

sDayName = Format(Day(11/1/2016), "dddd")

Then the output produces an incorrect Day Name which is:

sDayName = "Sunday"

when it's supposed to be "Tuesday". Thanks for the help guys.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For your specific request, assuming your date string is formatted as your regional setings:

    sDayName = Format("11/01/2016", "dddd")

If you want the weekday for today:

    sDayName = Format(Date, "dddd")

If you want the weekday for any date in any regional settings

    sDayName = Format(DateSerial(2016, 11, 4), "dddd")
    'change 2016, 11, 4 for your year, month, day values

:)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...