SQL Server convert string to datetime(SQL Server 将字符串转换为日期时间)
问题描述
这不是问如何在 MSSQL 中将任意字符串转换为日期时间,例如 this问题.
This is not asking how to convert an arbitrary string to datetime in MSSQL such as this question.
我可以控制字符串格式,但我想知道使用日期字符串更新日期时间字段的 MSSQL 语法是什么.
I can control the string format but I want to know what the MSSQL syntax is for updating a datetime field using a date string.
推荐答案
比如你可以使用
update tablename set datetimefield='19980223 14:23:05'
update tablename set datetimefield='02/23/1998 14:23:05'
update tablename set datetimefield='1998-12-23 14:23:05'
update tablename set datetimefield='23 February 1998 14:23:05'
update tablename set datetimefield='1998-02-23T14:23:05'
您需要注意日/月顺序,因为如果没有首先指定年份,这将取决于语言.如果您先指定年份,则没有问题;日期顺序将始终为年-月-日.
You need to be careful of day/month order since this will be language dependent when the year is not specified first. If you specify the year first then there is no problem; date order will always be year-month-day.
这篇关于SQL Server 将字符串转换为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server 将字符串转换为日期时间
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
