Just a quick post today to cover, what appears to be, a simple question.
How can I add a Time value to a Date value?
Static Dates with a Static Time Defined
So say you have a date value (US format – mm/dd/yyyy) of 9/19/2018 and you wanted to append a time value of 7:30 AM, how can this be done?
Well, this is where one has to be aware of a function like TimeSerial(), similar to DateSerial() but for times. Thus, the solution is remarkably simple and would look like
#9/19/2018# + TimeSerial(7,30,0)
Dynamic Dates with a Static Time Defined
Another common use is that we need to build queries/code that uses todays date, using the Date() function, but need the criteria to include a specific time. Well, the same approach can be used in such a scenario as well, and the expression/code would look something like
Date() + TimeSerial(7,30,0)
Another example
Below we want to add the time of 7:30 AM to a date 5 days in the future
DateAdd("d",5,Date()) + TimeSerial(7,30,0)
As you can see, the basic principle can be applied to pretty much any existing code.
Continue reading →