Ram Singh
Ram Singh

Reputation: 6938

how to compare two dates in C# Without comparing the time?

I want to compare two dates in C# i have tried Toshortdate() but its not working for me i dont know why? I just want to compare the dates not the time.. My code is as below:

 Convert.ToDateTime(b.CreatedDate).ToShortDateString() == Convert.ToDateTime(objbreedable.LastBDate).ToShortDateString()

Please help me.

Upvotes: 1

Views: 12803

Answers (1)

Jonas T
Jonas T

Reputation: 3077

Use Date property.

Convert.ToDateTime(b.CreatedDate).Date == Convert.ToDateTime(objbreedable.LastBDate).Date

Upvotes: 3

Related Questions