Importing Date in a .csv file.

Pierre Velluet 1 Reputation point
2023-02-08T08:02:35.75+00:00

Hello dear support,

I have a problem regarding an import of datatype Date from a .csv file.

The problem is described in the attached screenshit:

  • I do import correctly dates in the blue rectangle ( because it can only be a dd/MM/yyyy i suggest), like 13/09/2022. Perfect
  • But when the script read the records in the red rectangle, the value from .Value.ToString() switch to MM/dd/yyyy (09/12/2022) instead of beeing (12/09/2022).

I tried various solution, including parsing in code, but also trying to parse the column / cells of the sheet, before actually reading the value. Nothing worked so far.

The sheet cells format for the column in the excel document is of type Date / French.

The above code is just the one I use for creating my record, from the Row object named "ligne". Im using Devexpress.spreaSheet.Workbook library, in order to treat the Excel file. Please see attached a sample of the excel file. Unfortunatly, I can't attach a sample .CSV sample file ... Format unsupported here.

private static void CrerEcritureBancaire(Session session, FichierEcrituresBanque fichier, Row ligne, decimal débit, decimal crédit)
        {
            EcritureBancaire écritureBancaire = new EcritureBancaire(session);
            fichier.EcrituresBancaires.Add(écritureBancaire);

            écritureBancaire.Date = DateTime.ParseExact(ligne[0].Value.ToString().Split()[0], "dd/MM/yyyy", CultureInfo.CurrentCulture);

            écritureBancaire.Montant = débit == 0 ? crédit : débit;
            écritureBancaire.Référence = ligne[1].Value.ToString();
            écritureBancaire.Libellé = ligne[2].Value.ToString();
            écritureBancaire.Détails = ligne[5].Value.ToString();
        }

Could you provide me a solution or a lead to resolve this issue ?

Best regards, PierreSnapshot_230208115438

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,687 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,640 questions
{count} votes