--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)