A DateTime is always going to contain a time element in it even if you retrieve just the date from SQL server, or chop the time off in code with something like DateTime test1 = test2.Date; where test2 is also a DateTime.
You can compare two date parts for equality with something like DateTime.Compare(date1.Date,date2.Date); but what you are actually comparing is the date and time returned from the .Date method (midnight on the selected date).
You can write out just the date part with something like date1.ToString("d");
frez
Contributor
5418 Points
913 Posts
Re: How to read only date from sql server in asp?
Dec 22, 2010 07:58 AM|LINK
A DateTime is always going to contain a time element in it even if you retrieve just the date from SQL server, or chop the time off in code with something like DateTime test1 = test2.Date; where test2 is also a DateTime.
You can compare two date parts for equality with something like DateTime.Compare(date1.Date,date2.Date); but what you are actually comparing is the date and time returned from the .Date method (midnight on the selected date).
You can write out just the date part with something like date1.ToString("d");