Click here to Skip to main content
11,647,170 members (70,816 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
How to retrieve time as time itself rather than date time while reading to datatable from excel sheet via C# Code behind
Posted 24-Apr-13 10:07am
Comments
richcb at 24-Apr-13 16:16pm
   
DateTime has a .ToString() method where you can specify the display. Use "hh:mm:ss" to get only the time.
Sergey Alexandrovich Kryukov at 24-Apr-13 16:24pm
   
Sorry, a bad idea. One could take TimeOfDay, for example:
http://msdn.microsoft.com/en-us/library/system.datetime.timeofday.aspx
Anything, but not working with string representing time instead of time itself. How could it help?
—SA
richcb at 24-Apr-13 16:28pm
   
You are right, as usual. Thank you for the lesson.
Sergey Alexandrovich Kryukov at 24-Apr-13 16:29pm
   
You are always very welcome.
—SA
Sergey Alexandrovich Kryukov at 24-Apr-13 16:24pm
   
What does it mean: "reading to database"? Finally, reading or writing?
—SA

1 solution

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

Solution 1

Excel stores time values as Date[^] (DateTime[^] in C#). See here: Data types in Data Models (Excel)[^]

I think you need to format date as "time": Custom Date and Time Format Strings[^], String Format For DateTime (C#)[^]

DateTime date1 = new DateTime(2013, 4, 24, 19, 27, 15, 18);
CultureInfo ci = CultureInfo.InvariantCulture;
 
Console.WriteLine(date1.ToString("hh:mm:ss.f", ci));
// Displays 07:27:15.0
Console.WriteLine(date1.ToString("hh:mm:ss.F", ci));
// Displays 07:27:15
  Permalink  

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

  Print Answers RSS
0 jyo.net 500
1 OriginalGriff 337
2 DamithSL 310
3 Sergey Alexandrovich Kryukov 265
4 CPallini 249
0 OriginalGriff 1,277
1 jyo.net 994
2 DamithSL 946
3 Sergey Alexandrovich Kryukov 853
4 CPallini 760


Advertise | Privacy | Mobile
Web01 | 2.8.150804.2 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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