Hi
I have below excel sheet . In third column i have Hr & Min nut it show Dates also with it when i Upload Data
String Time = colum[2].ToString();
Below is the Excel Data
Col1 Col2 Col3
| 13 | 01/04/2022 | 14:30 |
| 18 | 02/04/2022 | 16:00 |
| 13 | 03/04/2022 | 17:15 |
Hi
I have below excel sheet . In third column i have Hr & Min nut it show Dates also with it when i Upload Data
String Time = colum[2].ToString();
Below is the Excel Data
Col1 Col2 Col3
| 13 | 01/04/2022 | 14:30 |
| 18 | 02/04/2022 | 16:00 |
| 13 | 03/04/2022 | 17:15 |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Mar 27, 2022, 8:13 AM EDT
Jagjit SainiRank #6,453 · 266 reputationPosted Mar 27, 2022, 8:30 AM EDT
Hi Muhammad
In Excel it is entered as 14:30 but when uploaded in variable Time it shows as - 31/12/1899 14:30:00
I have written like below now
String Time = colum[2].ToString();
DateTime fullDate = DateTime.ParseExact(Time, "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture);
string timeOnly = fullDate.ToString("HH:mm");
Below is Excel Data
col1 col2 col3
Thanks
Sachin SinghRank #66 · 26.2K reputationPosted Mar 27, 2022, 10:33 AM EDT
string timeOnly = fullDate.ToShortTimeString();Jagjit SainiRank #6,453 · 266 reputationPosted Mar 27, 2022, 10:53 AM EDT
Hi Sachin
It gives error on this line . Input string not in correct format
DateTime fullDate = DateTime.ParseExact(Time, "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture);
Thanks
Sachin SinghRank #66 · 26.2K reputationPosted Mar 27, 2022, 11:09 AM EDT
try this
DateTime dateTime = DateTime.ParseExact(colum[2].ToString(), "HH:mm", CultureInfo.InvariantCulture);
Jagjit SainiRank #6,453 · 266 reputationPosted Mar 27, 2022, 11:21 AM EDT