如何在存储过程中获取getdate()的子字符串 [英] how to take substring for getdate() in stored procedure

查看:126
本文介绍了如何在存储过程中获取getdate()的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我在这里使用get函数...但是我想在某个地方显示日期,但是它显示了完整的日期和时间...所以如何从中得出结论..

hello

I am using get function here...but somewhere i want to display the date but it is showing full date and time...so how to come up from this..

if(@flag=1)
begin
insert into tbl_DealerReqitems(Dealer_name,message,Email,mobile,phone,company,
address,category,sub_category,product,quantity,date,Status) values(@Dealer_name,@message,@Email,@mobile,@phone,@company,
@address,@category,@sub_category,@product,@quantity,GETDATE(),@Status)
end
if(@flag=2)
begin
select * from tbl_DealerReqitems where RequestID=@RequestID
end
if(@flag=3)
begin
end

推荐答案


检查此
http://blog .sqlauthority.com/2007/06/10/sql-server-retrieve-select-only-date-part-from-datetime-best-practice/ [ http://stackoverflow. com/questions/113045/how-to-return-the-date-part-only-from-a-sql-server-datetime-datatype [ http://www.sql-server-helper.com/functions/get-date- only.aspx [^ ]
http://msdn.microsoft.com/en-us/library/ms188383.aspx [ ^ ]
最好的问候
M.Mitwalli
Hi ,
Check this
http://blog.sqlauthority.com/2007/06/10/sql-server-retrieve-select-only-date-part-from-datetime-best-practice/[^]
http://stackoverflow.com/questions/113045/how-to-return-the-date-part-only-from-a-sql-server-datetime-datatype[^]
http://www.sql-server-helper.com/functions/get-date-only.aspx[^]
http://msdn.microsoft.com/en-us/library/ms188383.aspx[^]
Best Regards
M.Mitwalli


使用转换 [ ^ ]函数.
Use CONVERT[^] function.
SELECT CONVERT(NVARCHAR(10), GETDATE(),101) AS [US DateFormat]


我不建议转换日期时间完全串起来.如果要从GETDATE()结果中删除时间部分,请将其转换为日期.这样,您仍然可以使用日期值,而不会在不同区域性的不同格式上出现问题.

例如,尝试以下操作:
I wouldn''t advice to convert the datetime to string at all. If you want to remove the time portion from GETDATE() result, cast it as date. This way you can still work with a date value without possible problems on different formats in different culture.

For example try the following:
select convert(date,getdate())


这篇关于如何在存储过程中获取getdate()的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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