检查日期是否在vba中的2个日期之间

时间:2015-03-18 09:59:27

标签: vba excel-vba excel

我有4个字符串值:

Dim start As String,end As String,day1 As String,day2 As String
start="15/01/2015"
end="25/03/2015"
day1="20/02/2015"
day2="18/04/2015"

我想有一个函数来测试一天(day1或day2)是否在两个日期(开始和结束)之间,例如,它返回true为day1,false为day2。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

Function BetweenDates(startDate As String, endDate As String, testDate As String) As Boolean
    BetweenDates = IIf(CDate(testDate) > CDate(startDate) And CDate(testDate) <= CDate(endDate), True, False)
End Function