存储过程中的dateformat函数 [英] dateformat function in stored procedure

查看:138
本文介绍了存储过程中的dateformat函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DateFormat函数用于将日期转换为任何格式。但此函数无法在存储过程中使用。我尝试在存储过程中转换分钟格式(hh:mi:ss),但它无法正常工作。告诉''dateformat是无效的函数名''。

这是我的代码。



DateFormat function used to convert date to any format.But This function cant be used in Stored procedure.i have try to convert minute to time format(hh:mi:ss) in stored procedure ,but it is not working.it tells that ''dateformat is not valid function name''.
here is my code.

Select @TotalMin=(@Total_Min_of_StartTime + @Total_Min_of_EndTime)/2

	select @MidTime= DateFormat(@TotalMin,''%r'') 

推荐答案

日期格式可用在SQL Server中。查看以下所有格式的链接



http://www.codeshode.com/2011/06/sql-server-datetime-format-chart.html [ ^ ]
Date formats are available in SQL Server. Check this link below for all formats

http://www.codeshode.com/2011/06/sql-server-datetime-format-chart.html[^]


DateFormat函数用于将日期转换为任何格式

谁这样说?在此处阅读: MSDN:SET DATEFORMAT(Transact-SQL) [ ^ ] - 设置月,日和年的顺序解释日期,smalldatetime,datetime,datetime2和datetimeoffset字符串的日期部分。



如果你想提取日期的某些部分:MSDN:DATEPART(Transact-SQL) [ ^ ]



如果您正在寻找日期格式:< a href =http://msdn.microsoft.com/en-IN/library/ms187928.aspx> MSDN:CAST和CONVERT(Transact-SQL) [ ^ ]

示例:

DateFormat function used to convert date to any format
Who said so? Read about it here: MSDN: SET DATEFORMAT (Transact-SQL)[^] - Sets the order of the month, day, and year date parts for interpreting date, smalldatetime, datetime, datetime2 and datetimeoffset character strings.

If you are looking to extract certain part of date: MSDN: DATEPART (Transact-SQL)[^]

If you are looking for date formatting: MSDN: CAST and CONVERT (Transact-SQL)[^]
Sample:
SELECT
   '2006-04-25T15:50:59.997' AS UnconvertedText,
   CAST('2006-04-25T15:50:59.997' AS datetime) AS UsingCast,
   CONVERT(datetime, '2006-04-25T15:50:59.997', 126) AS UsingConvertFrom_ISO8601 ;
GO


这篇关于存储过程中的dateformat函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆