简体   繁体   English

将DATE_FORMAT转换为SQL Server函数

[英]Convert DATE_FORMAT to SQL Server function

Have migrated my database from mysql to SQL Server. 我的数据库已从mysql迁移到SQL Server。 When I run my query I get the error: 当我运行查询时,出现错误:

'DATE_FORMAT' is not a recognized built-in function name. 'DATE_FORMAT'不是公认的内置函数名称。

This is the query, where I am trying to convert the date as it's saved in the database 2014/03/03 to 03/03/2014 (DMY). 这是查询,我试图将保存在数据库2014/03/03中的日期转换为03/03/2014(DMY)。

This is the query: 这是查询:

DATE_FORMAT(routines.date, '%d/%m/%Y') as Dato

Use this: 用这个:

select CONVERT(varchar(12),getdate(),105)

See this for the various options. 对各种选项。

I like to use it in the beginning of my query 我喜欢在查询开始时使用它

SET DATEFORMAT DMY --Day/Month/Year ... you can write YMD or another combination

Syntax: 句法:

SET DATEFORMAT { format | @format_var } 

You can see examples in microsoft techNet 您可以在Microsoft TechNet中查看示例

If you want to use CONVERT in your SELECT clause you can use: 如果要在SELECT子句中使用CONVERT ,则可以使用:

SELECT convert(varchar, getdate(), 100) -- mon dd yyyy hh:mmAM (or PM) – Oct  2 2008 11:01AM          
SELECT convert(varchar, getdate(), 101) -- mm/dd/yyyy - 10/02/2008                  
SELECT convert(varchar, getdate(), 102) -- yyyy.mm.dd – 2008.10.02  
SELECT convert(varchar, getdate(), 105) -- dd-mm-yyyy 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM