如何获得日期的天数 [英] How to get the days for the date
本文介绍了如何获得日期的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
第 1 部分
Dim totdays as long
totdays = DateDiff("d", "01/2011", DateAdd("m", 1, "01/2011"))
上面的代码会返回31"
The above code will return "31"
我想得到那个 31 的日子
I want to get the days for that 31
预期输出
Monday (31/01/2011)
需要 VB6 代码帮助
Need VB6 Code Help
第 2 部分
我想找到特定月份的星期日....
I want to find the sundays on the particular month....
例如,如果我选择 01/2012 月份,查询应该给出这样的结果
For Example, If i select the month 01/2012, The query should give the result like this
01
08
15
22
29
以上日期为星期日.
01/2012
月的预期输出
01
08
15
22
29
推荐答案
something like this (tested in vba)
something like this (tested in vba)
周日子查询的最终更新
根据下面 Gopal 评论中的要求
As per request in commentd from Gopal below
Dim strDate As String
Dim dtStart As Date
Dim dtEnd As Date
Dim stEnd As Date
Dim lngCnt As Long
Dim strOut As String
strDate = "01/2012"
dtStart = DateValue(strDate)
dtEnd = DateAdd("d", DateDiff("d", strDate, DateAdd("m", 1, strDate) - 1), dtStart)
lngCnt = Weekday(dtStart) - 7
Do
lngCnt = lngCnt + 7
strOut = strOut & Format(lngCnt, "00") & vbNewLine
Loop While lngCnt + 7 <= dtEnd - dtStart
MsgBox strOut
更新
请注意,我需要使用 lngdays-1
来添加不到一个月的 1 天(即 31-Jan-2011),否则结果将是 01-Feb-2011
Note that I needed to use lngdays-1
to add 1 day less than a month (ie 31-Jan-2011), else you would have had 01-Feb-2011 as the result
Dim strDate As String
Dim lngdays As Long
strDate = "01/2011"
lngdays = DateDiff("d", strDate, DateAdd("m", 1, strDate))
MsgBox Format(DateAdd("d", lngdays - 1, strDate), "dddd (dd/mm/yyyy)")
旧
Dim lngdays As Long
lngdays = DateDiff("d", "01/2011", DateAdd("m", 1, "01/2011"))
MsgBox Format(DateSerial(2011, 1, lngdays), "dddd (dd/mm/yyyy)")
这篇关于如何获得日期的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文