SQL get current time (date)

Source: Internet
Author: User

--Get the current date (for example: YYYYMMDD)
Select CONVERT (nvarchar), GETDATE (), 112)

--Get the current date (for example: YYYYMMDD hh:MM:ss)
Select GETDATE ()

--Get the current date (for example: YYYY-MM-DD)
Select Datename (Year,getdate ()) + '-' +datename (Month,getdate ()) + '-' +datename (Day,getdate ())

--Get the current date (for example: YYYY/MM/DD)
Select Datename (Year,getdate ()) + '/' +datename (Month,getdate ()) + '/' +datename (Day,getdate ())

--Get several dates
Select Datename (Year,getdate ())-year (YYYY)
Select Datename (Yy,getdate ())

Select Datename (Mm,getdate ())--month
Select Datename (Dd,getdate ())--date
Select Datename (Hh,getdate ())--Get hours
Select Datename (Mi,getdate ())--Get minutes
Select Datename (Second,getdate ())--Get seconds
Select Datename (Week,getdate ())--Gets the current week (week) is the first week of the Year (week)
Select Datename (Weekday,getdate ())--Days of the week


--Date conversion
--for example 2011-10-24 15:57:16
Select CONVERT (varchar, GETDATE (), 120)

Select CONVERT (Varchar,getdate (), 111) + ' +datename (hh,getdate ()) + ': ' +datename (Mi,getdate ()) + ': ' +datename (SECOND, GETDATE ())

--such as 20111024155657
Select Replace (replace (CONVERT (varchar, GETDATE (), 120), '-', '), ', '), ': ', ')

-for example, 2011/10/24
Select CONVERT (varchar), GETDATE (), 111)

--such as 20111024
Select CONVERT (varchar), GETDATE (), 112)

-for example, 2011.10.24
Select CONVERT (varchar), GETDATE (), 102)

-for example, 10/24/2011
Select CONVERT (varchar), GETDATE (), 101)

-for example, 24/10/2011
Select CONVERT (varchar), GETDATE (), 103)

--such as 24.10.2011
Select CONVERT (varchar), GETDATE (), 104)

-for example, 24-10-2011
Select CONVERT (varchar), GETDATE (), 105)

--for example 24 10 2011
Select CONVERT (varchar), GETDATE (), 106)

--for example 10 24, 2011
Select CONVERT (varchar), GETDATE (), 107)

-for example 16:01:18
Select CONVERT (varchar), GETDATE (), 108)

--for example 10 24 2011
Select CONVERT (varchar), GETDATE (), 109)

-for example, 10-24-2011
Select CONVERT (varchar), GETDATE (), 110)

--for example 24 10 2011 1
Select CONVERT (varchar), GETDATE (), 113)

--such as 16:04:27:590 (590 milliseconds)
Select CONVERT (varchar), GETDATE (), 114)

--date format: Yyyy/mm/dd hh:mm:ss
Select CONVERT (varchar), GETDATE (), 111) + ' +datename (hh,getdate ()) + ': ' +datename (Mi,getdate ()) + ': ' + datename ( Second,getdate ())

--date format: Yyyy-mm-dd hh:mm:ss
Select CONVERT (varchar (+), GETDATE (), +) + ': ' +datename (Millisecond,getdate ()) + ': ' +datename (Mcs,getdate ())

Select CONVERT (varchar (+), GETDATE (), +) + ': ' + datename (millisecond,getdate ())

SQL get current time (date)

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.