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
CodePudding user response:
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