0% found this document useful (0 votes)
41 views

08 SQL Functions and Joins

The document discusses the DATEADD SQL function, which adds or subtracts a time interval from a specified date part. It lists the date parts that can be used, which are year, month, day, and week. It also explains the number represents the amount to increase or decrease the date part by, and the date is the value the interval will be added to. The code sample then demonstrates using DATEADD to add intervals like quarters, months, days, weeks, hours and more to a datetime value.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

08 SQL Functions and Joins

The document discusses the DATEADD SQL function, which adds or subtracts a time interval from a specified date part. It lists the date parts that can be used, which are year, month, day, and week. It also explains the number represents the amount to increase or decrease the date part by, and the date is the value the interval will be added to. The code sample then demonstrates using DATEADD to add intervals like quarters, months, days, weeks, hours and more to a datetime value.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Information Management - SY2122-2T

08 SQL Functions and Joins (Final)

NAME: VALIDO, MARK ANGELO A.


COURSE: BSIT-402

DATEADD (datepart, number, date)

 Datepart: It specifies the part of the date in which we want to add or subtract specific time
interval. It can have values such as year, month, day, and week. We will explore more in this
in the example section
 Number: It is the number by which we want to increase or decrease date. It should be an
integer
 Date: We can specify the date here. In this date, we want to add a specified number on
datepart

CODES:

DECLARE @Date datetime2;  


SET @Date = '2019-04-29 01:01:01.1111111';
Select DATEADD(quarter,1,@Date),
DATEADD(month,11,@Date)
,DATEADD(dayofyear,265,@Date)
, DATEADD(day,265,@Date)      
, DATEADD(week,4,@Date)  
, DATEADD(weekday,29,@Date)
, DATEADD(hour,11,@Date)    
, DATEADD(minute,59,@Date)
, DATEADD(second,01,@Date)
, DATEADD(millisecond,1,@Date);

You might also like