DateValue
will return only the date. CDate
will preserve the date and time:
? DateValue("2014-07-24 15:43:06")
24/07/2014
? CDate("2014-07-24 15:43:06")
24/07/2014 15:43:06
Similarly you can use TimeValue
to return only the time portion:
? TimeValue("2014-07-24 15:43:06")
15:43:06
? TimeValue("2014-07-24 15:43:06") > TimeSerial(12, 0, 0)
True
Also, as guitarthrower says, DateValue
(and TimeValue
) will only accept String
parameters, while CDate
can handle numbers as well. To emulate these functions for numeric types, use CDate(Int(num))
and CDate(num - Int(num))
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…