Click here to Skip to main content
13,799,906 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
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
Posted 6-Dec-18 18:16pm
Updated 6-Dec-18 18:31pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try casting to equivalent data types. For example
SELECT CAST(GETDATE() AS date)

SELECT CAST(GETDATE() AS time)

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.
  Permalink  
v3
Comments
MadMyche 7-Dec-18 10:36am
   
Agree 100%. Dates and times should always be of the DateTime type. How it appears to someone is a Presentation item. The maximum savings of 2 bytes per row is offset by the overhead of having double the columns for the one value.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.181214.1 | Last Updated 7 Dec 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100