SQL Server将字符串转换为datetime [英] SQL Server convert string to datetime

查看:932
本文介绍了SQL Server将字符串转换为datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是问如何将任意字符串转换为MSSQL中的datetime,例如这个问题

This is not asking how to convert an arbitrary string to datetime in MSSQL such as this question.

我可以控制字符串格式,但我想知道使用日期字符串更新datetime字段的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.

推荐答案

似乎这是由Tibor Karaszi非常充分地回答。例如,您可以使用

Seems that this is answered very adequately by Tibor Karaszi. For instance you can use

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'

请参阅Tibor的页面进行全面的讨论。您需要注意日/月订单,因为当年没有指定时,这将依赖于语言。如果您先指定第一个,那么没有问题;日期订单将始终为年月日。

Refer to Tibor's page for a full discussion. 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将字符串转换为datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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