本文介绍了如何使用C#在SQL表中从datetime分割日期n时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i want to spilt datetime into date and time in their separate column at the time of insert record.
so need guide for this thanks... 





我尝试过:





What I have tried:

SELECT     CONVERT(VARCHAR(7), EndDate, 114) AS Time
FROM         Country

推荐答案

SELECT CAST(GETDATE() AS date)

SELECT CAST(GETDATE() AS time)



如果要将它们分开在C#方面,将数据读入 []变量并使用

- []

- 或 []



作为旁注,在插入行时将日期和时间分成单独的列可能不太好理念。您始终可以从单个列中拆分所需的信息,因此为单个时间点添加两个单独的列会使事情变得不必要。


If you want to separate them on the C# side, read the data into a DateTime[^] variable and use either
- DateTime.Date Property (System) | Microsoft Docs[^]
- or DateTime.TimeOfDay Property (System) | Microsoft Docs[^]

As a side note, breaking the date and time into separate columns when inserting a row might not be a good idea. You can always split the information needed from a single column so adding two separate columns for a single point-in-time makes things unnecessary complicated.


这篇关于如何使用C#在SQL表中从datetime分割日期n时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 22:46