开发者

Check if one given date is between two dates several years apart?

开发者 https://www.devze.com 2023-02-20 22:26 出处:网络
Todays date is 31.03.2011 (European, at least). A hotel room is booked from, lets say, 23.02.2011 to 05.05.2013 (yes, over two years!).

Todays date is 31.03.2011 (European, at least). A hotel room is booked from, lets say, 23.02.2011 to 05.05.2013 (yes, over two years!).

How can I chec开发者_如何学编程k if todays date is in between the reserved dates or not?

Ideally I want to sort it into an boolean array of 3 dimensions, like date(year,month,day) and TRUE means "booked".

Preferred language is VBScript because this is my only option, but Java/C whatever is also okay to use as an example to work from (text explaining the solution is of course also okay).

Thank you!


Don;t know VBScript but the time/date library can normally return times in an integer format (typically seconds since 1970). Just convert the three dates to this format and check using the normal compare operators


VBScript Functions notes a Datedifffunction that you could use with the 3 variables representing each point in time. Course there are other solutions to this like converting the date to another type and using that for comparison,e.g. concatenate yyyyMMdd into an integer and compare them that way.


checkIn=DateSerial(2011,02,23)
checkOut=DateSerial(2013,05,05)
testMe=Now

If testMe>checkIn And testMe<checkOut Then
    MsgBox("Living the good life.")
End If
0

精彩评论

暂无评论...
验证码 换一张
取 消