excel vba-如何获取日期的日期名称? [英] excel vba - How to get the Day Name of Date?

查看:674
本文介绍了excel vba-如何获取日期的日期名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小代码,可以获取Excel中列出的日期的天名称。但是问题是,它没有正确的日期名称(例如星期二)。

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).

例如:

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

然后,输出产生不正确的Day Name,即: / p>

Then the output produces an incorrect Day Name which is:

sDayName = "Sunday"

,应为星期二。
感谢您的帮助。

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

推荐答案

对于您的特定请求,假设您的日期字符串的格式设置为您的区域设置:

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

:)

这篇关于excel vba-如何获取日期的日期名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆