Date-Time Functions :

The available date time functions in sql are: -> getdate() -> getutcdate() -> current_timestamp The above functions will return current date and time values -> getdate() Syntax: select getdate() -> getutcdate Syntax: select getutcdate() -> current_timestamp Syntax: select current_timestamp Note: While wrting T-SQL code use current_timestamp function instead of getdate function.

Functions That get date time parts:

-> datename: DATENAME(datepart,date) returns nvarchar -> datepart:datepart(datepart,date) returns int -> day:day(date) returns int -> month:month(date) returns int -> year:(date) returns int Note: -> datepart can be any of the below given keywords years,quarter,month,dateof year,day,week,weekday,hour,minute,second,millisecond. -> Nested datetime functions are supported in T-SQL. -> While passing date-time values to datetime functions the date must be in mm/dd/yyyy format. Query to display employees in the descending order of their year of joining. -> select * from employees order by doj(year) desc. (or) select eid,fname,lname,age,salary,dept,year(doj) from employees arder by year(doj) desc. Query for updating employees salary by 190% for the employees who joined in the month of October. -> update employee set salary = 1.1*salary where month(doj)=10 Query to display employees details including joining day name in the descending order of joining of time. -> select eid,fname,lname,age,salary,dept datename(weekday,doj) as 'days' order by deesc from employees.

Functions That modify date and time values:

dateadd:DATEADD(datepart,NUMBER,DATE) returns varchar Ex: select DATEADD(DAY,10,'10/9/2011') as 'CHANGED DATE' datediff:DATEDIFF(datepart,startdate,enddate) returns int Ex:select DATEDIFF(year,'09/10/1969',16/10/2014') Query to add 10 moths to the date '7/23/2019' -> select dateadd(month,10,'7/23/2019') Query to add 20years,3months,4days to the given date '10/5/1998' -> select dateadd(day,4,dateadd(month,3,dateadd(year,20,10/5/1998))) Query for adding 5months,3days and 10years to the current date. -> select dateadd(month,5,dateadd(day,3,dateadd(year,10,getdate()))) as 'resultdate'