SQL Table日期时间列格式 [英] SQL Table datetime column format
本文介绍了SQL Table日期时间列格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用谷歌搜索找到答案,但徒劳无功.以下是我的要求
I tried googling to get an answer but in vain. Below is my requirement
- 用户可以选择将数据插入具有export_date作为datetime的表中
- 当他们执行插入语句时,我想确保他们以"dd-MM-yyyy hh:mm:ss"格式键入日期.如果不是,则不允许运行插入查询.
- 或者允许用户以dd-MM-yyyy或dd/MM/yyyy之类的任何格式输入日期,但在内部将其转换为所需的格式"dd-MM-yyyy hh:mm:ss"并存储
有人可以帮助/指导我吗?
Can someone help/guide me?
推荐答案
您可以使用设置DateFormat
示例
使用了 date
的数据类型进行说明,但是显然您可以使用 datetime
Used data type of date
for illustration, but clearly you can use datetime
Set DateFormat DMY
Select try_convert(date,'15/08/2017') -- Returns 2017-08-15
Set DateFormat MDY
Select try_convert(date,'15/08/2017') -- Returns NULL
Set DateFormat YMD
Select try_convert(date,'15/08/2017') -- Returns NULL
这篇关于SQL Table日期时间列格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文