Some sql server date manipulation functions

SQL Server built into some of the functions of the date of the operation, lists some common here.

1.getdate () function to get the current system date and time:

select getdate();

2.dateadd () function on the basis of the period of time specified plus date, datetime returns the new value:

select dateadd(day, 2, '2019-07-06'); -- 2019-07-08 00:00:00.000

3.datediff () function returns the number of date and time across the border two specified dates:

select datediff(day, '2019-07-01', '2019-07-06'); -- 5

4.datepart () function returns the specified date represents an integer portion of the date specified:

SELECT  the datepart ( month The , ' 2019-07-06 ' ); - Returns 7

5.datename () function returns the representative of the specified portion of the date specified date string:

SELECT  DATENAME (WEEKDAY, ' 2019-07-06 ' ); - Saturday

6.day () function returns the integer portion of the date specified date:

select day('2019-07-06'); -- 6

7.month () function returns the month part of a specified date

select month('2019-07-06'); -- 7

8.year () function returns the date portion of integer parts:

select year('2019-07-06'); -- 2019

9.cast () function date / string into a string / date:

cast(expression as data_type)

10.convert () function to convert the string / date is the date / string:

convert(data_type[(length)], expression [, style])

 

"If the people no matter what, what regarded himself as an exception, perhaps there would be so much disappointed."

Guess you like

Origin www.cnblogs.com/yanggb/p/11143452.html