SPIRINN
SPIRINN

Reputation: 73

Dapper return data type DATE with time

I have problem. I have MySQL database and I use DATE type for my date column. I want to save date without time only. In database date is saved like this 06/02/1999 for example. But when I try to take it with dapper

var test = connection.QueryFirstAsync<string>(@"SELECT BirthDate FROM Students");

Then it returns 06/02/1999 00:00:00 How can I fix that? I want string without that time that shouldn't even be there in first place. Thank you very much for answers

Upvotes: 0

Views: 4254

Answers (1)

ggeorge
ggeorge

Reputation: 1630

Simple (maybe naive) solution is this one:

string date = "06/02/1999 00:00:00";

DateTime dateTime = DateTime.Parse(date);
DateOnly dateOnly = DateOnly.FromDateTime(dateTime);

Note: DateOnly applies to .NET 6, .NET 7 Preview 6

Upvotes: 1

Related Questions