如何给出日期格式..? [英] how to give date format..?

查看:80
本文介绍了如何给出日期格式..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

declare @fromdate varchar(50)
declare @todate varchar(50)  
set @fromdate='2015/09/01'
set @todate='2015/09/30'
exec(@fromdate)
exec(@todate)







收到错误,请告诉我解决方案..





消息102,等级15,状态1,第1行

语法错误n ear'2015'。

消息102,等级15,状态1,行1

'2015'附近的语法不正确。




am getting error for this kindly tell me the solution..


Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '2015'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '2015'.

推荐答案

请阅读我对这个问题的评论。



日期是一个日期,没有别的!



如果你想添加日期,请使用适当的变量类型:



Please, read my comment to the question.

Date is a date and nothing else!

If you want to add date, use proper variable type:

DECLARE @fromdate DATE = '2015/10/01'





如果MS SQL Server无法识别这种格式,请使用: SET DATEFORMAT [ ^ ]命令。





If MS SQL Server can't recognize such of format, use: SET DATEFORMAT[^] command.

SET DATEFORMAT ymd;
DECLARE @fromdate DATE = '2015/10/01'





如需了解更多信息,请参阅:

CAST和CONVERT(Transact-SQL) [ ^ ]

日期和时间数据类型和功能(Transact- SQL) [ ^ ]


您好,



查看此...





Hi,

Check this...


declare @fromdate varchar(50)
declare @todate varchar(50)
set @fromdate='2015/09/01'
set @todate='2015/09/30'

SELECT @fromdate
SELECT @todate





希望这会对你有所帮助。 />


干杯



Hope this will help you.

Cheers


这篇关于如何给出日期格式..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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