1

我已经在 mysql 中格式化了一个日期列,DATE_FORMAT(enquiry.enquiryDate,'%d-%b-%Y') as enquiryDate现在我想要与此等效的 sql server 吗?

4

2 回答 2

2

你可以在这里看到一个使用转换的例子:

http://www.sql-server-helper.com/tips/date-formats.aspx

或在此处使用函数的示例:

http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/

SELECT dbo.fnFormatDate (getdate(), ‘MM/DD/YYYY’)           – 01/03/2012

SELECT dbo.fnFormatDate (getdate(), ‘DD/MM/YYYY’)           – 03/01/2012

SELECT dbo.fnFormatDate (getdate(), ‘M/DD/YYYY’)            – 1/03/2012

SELECT dbo.fnFormatDate (getdate(), ‘M/D/YYYY’)             – 1/3/2012

SELECT dbo.fnFormatDate (getdate(), ‘M/D/YY’)               – 1/3/12

SELECT dbo.fnFormatDate (getdate(), ‘MM/DD/YY’)             – 01/03/12

SELECT dbo.fnFormatDate (getdate(), ‘MON DD, YYYY’)         – JAN 03, 2012

SELECT dbo.fnFormatDate (getdate(), ‘Mon DD, YYYY’)         – Jan 03, 2012

SELECT dbo.fnFormatDate (getdate(), ‘Month DD, YYYY’)       – January 03, 2012

SELECT dbo.fnFormatDate (getdate(), ‘YYYY/MM/DD’)           – 2012/01/03

SELECT dbo.fnFormatDate (getdate(), ‘YYYYMMDD’)             – 20120103

SELECT dbo.fnFormatDate (getdate(), ‘YYYY-MM-DD’)           – 2012-01-03

– CURRENT_TIMESTAMP returns current system date and time in standard internal format

SELECT dbo.fnFormatDate (CURRENT_TIMESTAMP,‘YY.MM.DD’)      – 12.01.03

GO
于 2010-07-06T06:02:16.770 回答
0

您可以使用该CONVERT功能 - 例如:

SELECT CONVERT(VARCHAR(11), GETDATE(), 106)

这里有一个格式列表:

http://www.sql-server-helper.com/tips/date-formats.aspx

还有更多信息:

http://msdn.microsoft.com/en-us/library/ms187928.aspx

于 2010-07-06T06:10:19.997 回答