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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Muhammad Imran AnsariPosted Mar 27, 2022, 12:13 PM
Jagjit SainiPosted Mar 27, 2022, 3:21 PM
Sachin SinghPosted Mar 27, 2022, 3:09 PM
try this
DateTime dateTime = DateTime.ParseExact(colum[2].ToString(), "HH:mm", CultureInfo.InvariantCulture);
Jagjit SainiPosted Mar 27, 2022, 2:53 PM
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 SinghPosted Mar 27, 2022, 2:33 PM
Jagjit SainiPosted Mar 27, 2022, 12:30 PM
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