Replies: 2 comments 8 replies
-
Where would you be looking at the data? You could create an extra property like |
Beta Was this translation helpful? Give feedback.
1 reply
-
I'm not sure how that compiles as Here is an example. void Main()
{
var s = new StringBuilder();
s.Append($"Id,Name,EndDate\r\n");
s.Append($"1,one,{new DateTime(2021, 4, 13)}\r\n");
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
};
using (var reader = new StringReader(s.ToString()))
using (var csv = new CsvReader(reader, config))
{
csv.Context.RegisterClassMap<FooMap>();
csv.GetRecords<Foo>().ToList().Dump();
}
}
private class Foo
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime? EndDate { get; set; }
public bool IsEndDateMidnight { get; set; }
}
private class FooMap : ClassMap<Foo>
{
public FooMap()
{
Map(m => m.Id);
Map(m => m.Name);
Map(m => m.EndDate);
Map(m => m.IsEndDateMidnight).Convert(args =>
{
var endDate = args.Row.GetField<DateTime?>(nameof(Foo.EndDate));
if (endDate == null)
{
return false;
}
return endDate.Value.Hour == 0 && endDate.Value.Minute == 0 && endDate.Value.Second == 0 && endDate.Value.Millisecond == 0;
});
}
} |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When reading a field that is specified as a DateTime if the CSV only contains a date the time portion is set to midnight (00:00:00). Is there any way to tell if the CSV just contained the date portion (and the time was set to midnight automatically on reading) or if the CSV actually contained a time portion of 00:00:00?
Beta Was this translation helpful? Give feedback.
All reactions