Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nullable-How to compare only Date without Time in DateTime types in C#?

Tags:

c#

.net

datetime

How to compare only Date without Time in DateTime types in C#.One of the date will be nullable.How can i do that??

like image 783
vmb Avatar asked Oct 18 '25 03:10

vmb


1 Answers

DateTime val1;
DateTime? val2;

if (!val2.HasValue)
    return false;

return val1.Date == val2.Value.Date;
like image 50
landoncz Avatar answered Oct 19 '25 17:10

landoncz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!