I can’t find a way to find all the dates(strings) less then at least one year from now.
i keep in database Date Field strings like “DateTime.toShortDateString()” and i need to compare now.
it looks like month/day/year = 9/6/2011
its need to be lower at least one year from DateTime.now.
i did this and it doesnt return all dates needed just few.
DateTime Date = DateTime.Now;
int Year = Date.Year;
Year -= 1;
int Month = Date.Month;
string MonthYear = Month.ToString() + "%" + Year.ToString();
string Query = "SELECT * FROM Orders WHERE DateOrder < @STU ";
SqlCommand cmd = new SqlCommand(Query, con);
cmd.Parameters.AddWithValue("@STU", MonthYear);
This is my problem
Modify your database schema and store dates as
char(10)in ISO 8601 format (yyyy-mm-dd) or the ISO 8601 compact form (yyyymmdd).That gives you proper collation and proper comparison. Further…DateTime.Parse() and TryParse() will both accept that format regardless of culture (well..one exception: Saudi Arabia, ar-SA. Go figure).
DateTime.ToString("Y") orstring.Format( “{0:Y}” , someDateTimeInstance )` will give you the ISO 8601 format.Should be a simple update to your database.
Even better, if you’re using SQL Server 2008: store dates using the new datatype
Date.