DATEADD() – Sub-second Functions

I am a pertinacious in my creation of short articles or tidbits on Transaction SQL date/time functions.

Most, if not all, modern day computer systems collect data which contains dates and times. Many times you will want to add or subtract a fixed number of years, months, or etc from a date time variable.

Today, I will be exploring the DATEADD() function. This function has 13 different input parameters that can be passed to change the resulting output.

To summarize, the function takes a date part, a offset number, and date/time variables as input returns a new date/time variable adjusted by adding or subtracting the offset.

I will be exploring the three date part parameters that adjust date/time variable by a fixed sub-second time offset.

DATE PART PARAMETER TO USE
MILLISCOND MS
MICROSECOND MCS
NANASECOND NS

 

The examples below are sample calls to the function. The inputs puts are valid numeric offsets and date time variables.

The output from the test is listed below.

To make a long story short, pass one of the three date part parameters with a valid offset number to adjust your current date time variable. Next time, I will be talking about the DATEDIFF() function.

Related posts

Leave a Comment