I have a model that has a DateTime type property. From this property, I want to include the seconds and microseconds to the string when writing to CSV file and when reading from the CSV file through CsvHelper.

So here is how I came up with the solution by extending the **DefaultTypeConverter**

```
public class CsvDateTimeConverter : DefaultTypeConverter
{
    private const string DateStringFormat = "MM/dd/yyyy HH:mm:ss.fff";

    public override object ConvertFromString(TypeConverterOptions options, string text)
    {
        if (string.IsNullOrEmpty(text)) return null;

        return Convert.ToDateTime(text);
    }

    public override string ConvertToString(TypeConverterOptions options, object value)
    {
        if (value == null) return "";

        var dateTime = (DateTime) value;

        return dateTime.ToString(DateStringFormat);
    }
}

```

the model looks like this

```
public class MyModel
{
    // ..... removed other properties
    public DateTime MyDateTime {get; set};
}

```

And the CsvClassMapper looks like this

```
public sealed class CsvMap : CsvClassMap<MyModel>
{
    public CsvMap()
    {
        Map(m => m.MyDateTime).TypeConverter<CsvDateTimeConverter>();
    }
}

```

I registered the class map to the reader and writer. But the problem is:

I can successfully write to the CSV file using the converter but when I try to read from CSV file, it can read the other properties but returns null for the DateTime property.

So.. what am I missing?

**EDITED:**

if it helps:

this is the code to read from csv file:

```
using (TextReader reader = new StreamReader(filePath))
{
     var csv = new CsvReader(reader);
     csv.Configuration.RegisterClassMap<CsvMap>();

     csv.Configuration.Encoding = Encoding.UTF8;

     return csv.GetRecords<MyModel>().ToList();
 }

```