Sql server仅在dd mm yyyy中接受日期 [英] Sql server accept date only in dd mm yyyy

查看:78
本文介绍了Sql server仅在dd mm yyyy中接受日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我需要将日期插入我的datecolumn regdate,这是datetime数据类型。但是在插入之前我需要检查插入的日期是否是是dd mm yyyy格式与否。如果它是那种格式,那么我需要插入或不插入。



我用Isdate函数试过这样的,就像



SET LANGUAGE us_english

SET DATEFORMAT dmy



isdate('12 / 10/2013')/////返回1

isdate('12 / 13/2013')///////返回0

及其工作正常。



但如果我这样使用



SET LANGUAGE us_english;

SET DATEFORMAT dmy;

select isdate('2013/12/12')////返回1而不是0





非常感谢您的帮助。

解决方案

IsDate函数将返回true或false,具体取决于您传递的值是否为a适当的日期与否。



您可以在SQL中使用转换功能比较dd / MM / yyyy的日期 -



< pre lang =SQL> SELECT CONVERT VARCHAR ,GETDATE(), 103


如果要检查日期是否为如果格式正确,请使用 RegEx [ ^ ]。以下是一系列示例:正则表达式匹配有效日期 [ ^ ]。



MS SQL Server商店日期取决于许多设置 [ ^ ]。不要尝试以自定义格式存储日期。日期是日期,无论显示格式。你明白了吗?


Hello,

I need to insert date into my datecolumn regdate which is of datetime data type.But before inserting i need to check whether the date iam inserting is in dd mm yyyy format or not.If it is in that format,then i need to insert or else not.

I have tried like this with Isdate function,like

SET LANGUAGE us_english
SET DATEFORMAT dmy

isdate('12/10/2013') /////returns 1
isdate('12/13/2013') ///////returns 0
and its working fine.

but if i use like this

SET LANGUAGE us_english;
SET DATEFORMAT dmy;
select isdate('2013/12/12') ////returns 1 instead of 0


Thanks a lot for any help.

解决方案

IsDate Function will return true or false depending on whether the value you are passing is a proper date or not.

You can compare the date for dd/MM/yyyy with the help of Convert function in SQL -

SELECT CONVERT(VARCHAR,GETDATE(),103)


If you want to check if date is in proper format, please use RegEx[^]. Here is a collection of examples: Regular Expression Matching a Valid Date[^].

MS SQL Server stores dates depending on many settings[^]. Do not try to store date in custom format. Date is date, no matter of displaying format. Do you get it?


这篇关于Sql server仅在dd mm yyyy中接受日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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