这个mysql查询的sql server等效吗?

时间:2010-07-06 05:58:37

标签: mysql sql-server-2005 equivalent

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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