我无法让代码显示正确的日期。
DatePart("w", Now()) & _
代码显示为星期五,但我居住的地方是星期四。我怎么改-1天?
我和一个好人联系了这个网站!访问https://msdn.microsoft.com/en-us/library/4kt42529(v=vs.84).aspx但它不理解解释。
答案 0 :(得分:2)
DatePart("w", DateAdd("d",-1,Now()))
答案 1 :(得分:1)
使用
DatePart("w", Now(), vbMonday)
或(更好地随处可移动,与位置无关)
DatePart("w", Now(), vbUseSystemDayOfWeek)
<强>解释强>:
DatePart
函数返回给定日期的指定部分。
DatePart(interval, date[, firstdayofweek[, firstweekofyear]])
参数:
interval
必填。字符串表达式,是您要返回的时间间隔。有关值,请参阅“设置”部分。date
必填。您要评估的日期表达。firstdayofweek
可选。指定星期几的常量。 如果未指定,则假设星期日。firstweekofyear
可选。指定一年中第一周的常量。如果未指定,则假定第一周是1月1日发生的那一周。仅供参考:firstdayofweek
参数可以包含以下值:
Constant Value Description
vbUseSystemDayOfWeek 0 Use National Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
firstweekofyear
参数可以包含以下值:
Constant Value Description
vbUseSystem 0 Use National Language Support (NLS) API setting.
vbFirstJan1 1 Start with the week in which January 1 occurs (default).
vbFirstFourDays 2 Start with the week that has at least four days in the new year.
vbFirstFullWeek 3 Start with the first full week of the new year.