Ask Reuben 120 - Datetime Addition

Started by Reuben B., April 08, 2022, 05:35:32 AM

Previous topic - Next topic

Reuben B.

With DATETIME variables, a common requirement is to add a number of minutes to a DATETIME.

Developers occasionally get stuck and the reason I believe is that Implicit Type conversions occasionally get you into bad habits.  Sometimes you need to take a step back, use 3 lines of code instead of 1, then you can see the issue, and then see what the 1 line of code solution is.

With DATETIME addition, that can mean making sure that what you are attempting to add to the DATETIME is an INTERVAL, not a STRING.  It should be DATETIME + INTERVAL = DATETIME

Read more here https://4js.com/ask-reuben/ig-120/
Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero

Reuben B.

Rene reminded me about the UNITS operator which could shorten my example even further so I added a small paragraph and included that in the code example.

Reuben
Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero