Welcome to OGeek Q&A 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 Reply

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

:)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...