Click here to Skip to main content
16,019,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have some datas in excel sheet which contains time only. But when i upload those file into datatable i got the time column with date also. I dont want like this. I need time column only should be time only with out date. For example, I have time value in excel sheet 00:15:00. When i upload this to datatable i will get 02-02-2016 00:15:00 like this. I want time should be keep time only. How i to do that?
Posted
Comments
F-ES Sitecore 2-Feb-16 6:38am    
There are no time-only datatypes so you're always going to have the date as well. You're going to have to just ignore it. If you are going to what to do queries on a time range you'll need to make sure the dates are all the same date.

1 solution

Excel does not store just the time. Yes, you can format an Excel sheet to only show time but internally the date value is still there.

Since Sql 2008, sql has had a Time datatype for columns. time (Transact-SQL)[^]. So, if you are going to store this in SQL then you can write it out to sql with just the time.

However, if you are only going to be working with this in C# and your DataTable then here are a bunch of different examples of how to get just the time from a DateTime in C#, datetime - How to get only time from date-time C# - Stack Overflow[^].
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900