SQL Server date

Source: Internet
Author: User

--- The first day of a month
Select dateadd (mm, DATEDIFF (mm, 0, getdate (), 0)
--- Monday of this week
Select dateadd (wk, DATEDIFF (wk, 0, getdate (), 0)
--- The first day of a year
Select dateadd (yy, DATEDIFF (yy, 0, getdate (), 0)
---- The first day of the quarter
Select dateadd (qq, DATEDIFF (qq, 0, getdate (), 0)
---- Last day of last month
SELECT dateadd (MS,-3, DATEADD (mm, DATEDIFF (mm, 0, getdate (), 0 ))
---- Last day of last year
SELECT dateadd (MS,-3, DATEADD (yy, DATEDIFF (yy, 0, getdate (), 0 ))
---- The last day of this month
SELECT dateadd (MS,-3, DATEADD (mm, DATEDIFF (m, 0, getdate () + 1, 0 ))
----- The first Monday of this month
Select DATEADD (wk, DATEDIFF (wk, 0,
Dateadd (DD, 6-datepart (day, getdate (), getdate ())
), 0)
--- The last day of this year
Select dateadd (MS,-3, dateadd (YY, datediff (YY, 0, getdate () + 1, 0 )).

---- Conversion time format
Select convert (varchar (30), getdate (), 101) now

 

 

101/DD/yy
102 YY-mm-dd
103 dd/mm/yy
104 DD-mm-yy
105 DD-mm-yy
106 dd mon YY
107 mon DD, YY
108 hh: mm: SS
9 or 109 mon dd yyyy hh: MI: SS: mmmmam (or pm)
110-dd-yy
111 YY/MM/dd
112 yymmdd
13 or 113 dd mon yyyy hh: MI: SS: Mmm (in 24-hour format)
114 hh: MI: SS: Mmm (in 24-hour format)
20 or 120 | yyyy-mm-dd hh: MI: SS (in 24-hour format)
21 or 121 | yyyy-mm-dd hh: MI: SS: Mmm (in 24-hour format)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.