HI i made the followin class to get dates from an excel file.
file:
col:a col:b col:c
1. X-mas 2015-19-12 2016-03-01
2. carnaval 2016-20-02 2016-28-02
- using System;
- using OfficeOpenXml;
- using System.IO;
- namespace CalviVsTribessCheck.Cmd
- {
- public static class ExcelFileDataAccess
- {
- public static void ReadExcelFile(DateTime start)
- {
- var filePath = @"c:\code\Tools\Development\RtcMonitoring\RatingTribessCheck.Cmd\Vacations.xlsx";
- var sheetName = "vacations";
- using (var excelPkg = new ExcelPackage())
- using (var stream = new FileStream(filePath, FileMode.Open))
- {
- excelPkg.Load(stream);
- ExcelWorksheet oSheet = excelPkg.Workbook.Worksheets[sheetName];
- var totalRows = oSheet.Dimension.End.Row;
- for (var i = 1; i <= totalRows; i++)
- {
- var vacationbegindate = DateTime.Parse((oSheet.Cells[i, 1]).Value.ToString());
- var vacationenddate = DateTime.Parse((oSheet.Cells[i, 2]).Value.ToString());
- BusinessLogic.CheckVacation(start, vacationbegindate, vacationenddate);
- }
- }
- }
- }
- }
The string is not recognized as a valid DateTime. Index 0 begins with an unknown word
How can i fix this ???? please provide me with your answer
Rajeev PunhaniRank #551 · 4.4K reputationPosted Feb 25, 2016, 8:04 AM EST
If the above solution is helpful then,accept the answer.
Rajeesh MenothRank #118 · 18.4K reputationPosted Feb 25, 2016, 7:44 AM EST
Check the following reference :
http://www.c-sharpcorner.com/code/1459/string-was-not-recognized-as-a-valid-datetime.aspx
Banketeshvar NarayanRank #235 · 10.5K reputationPosted Feb 25, 2016, 7:55 AM EST
Cassie ModRank #3,821 · 387 reputationPosted Feb 29, 2016, 2:07 AM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts