Click here to Skip to main content
12,998,483 members (129,252 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
richcb 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 24-Apr-13 16:24pm
Sorry, a bad idea. One could take TimeOfDay, for example:
Anything, but not working with string representing time instead of time itself. How could it help?
Sergey Alexandrovich Kryukov 24-Apr-13 16:24pm
What does it mean: "reading to database"? Finally, reading or writing?
richcb 24-Apr-13 16:28pm
You are right, as usual. Thank you for the lesson.
Sergey Alexandrovich Kryukov 24-Apr-13 16:29pm
You are always very welcome.

1 solution

Rate this: bad
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

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 | Mobile
Web02 | 2.8.170622.1 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2017
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