Convert Varchar into Time in SQL Server(在 SQL Server 中将 Varchar 转换为时间)
问题描述
我如何将时间格式 " 10:02:22 PM " 转换为 SQL Server 日期时间格式.
How do i convert the Time format " 10:02:22 PM " into an SQL Server DateTime Format.
我有一列这样的数据.我从 CSV 文件导入了此列,现在想将其转换为日期时间格式,以便我能够使用日期时间函数.
I have a column of such data. I imported this column from a CSV File and now want to convert it into a DateTime Format so that i can be able to use Date Time Functions.
我希望能够将此列插入到另一个具有正确日期时间格式的表中.
I want to be able to insert this column into another table with correct DateTime format.
推荐答案
使用此链接:http://msdn.microsoft.com/en-us/library/ms187928.aspx.
仅用于时间转换...
SELECT CONVERT( TIME, '10:00:22 PM' );
给出以下输出...
22:00:22.000000
带有日期和时间的时间转换...
Time conversion with date and time...
SELECT CONVERT( DATETIME, '10:00:22 PM' );
给出以下输出...
1900-01-01 22:00:22.0000
注意:对于datetime,您需要将特定日期作为输入,否则会考虑默认世纪日期.
Note : For datetime you need to have specific date as input otherwise it consider default century date.
这篇关于在 SQL Server 中将 Varchar 转换为时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 SQL Server 中将 Varchar 转换为时间
基础教程推荐
- 是否可以执行按位分组功能? 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 无法解决整理冲突 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
