The format matters when you parse a string to a DateTime object. Once you have done that and you have two DateTime objects then comparing their Date properties is the correct thing to do. The Date properties return DateTime objects with time set to 12:00am
In order to parse the date correctly you can pass a IFormatProvider to the DateTime.Parse() method. E.g. a CultureInfo object:
DateTime d = DateTime.Parse("07/04/2011", CultureInfo.GetCultureInfo("en-us"));
Can this link help you?
where t.CreateDate.Date < DateTime.Today.AddMonths(-1)
The thing is that you will rarely compare dates in a specific format(unless you want to compare them as strings or something). Thus is the introduction of the DateTime structure.
Anyway the most used way of comparing dates is not to check for equality but to actually check whether a date comes into a specific range. For example:
startDate <= order.OrderDate && order.OrderDate < endDate
- Use Linq query to compare date only with DateTime field
- Compare only Date in nHibernate Linq on a DateTime value
- how does one compare the date part of a nullable datetime in a linq / lambda query?
- LINQ Source Code Available
- How to compare only date part with linq expression?
- creating Linq to sqlite dbml from DbLinq source code
- Linq compare by date problem
- Date compare in LINQ
- Linq compare string date
- How do I use LINQ to compare a date and a datetime?
- source code for LINQ 101 samples
- C# LINQ code for two list compare and replace
- How to compare Years in Linq for Date Fields?
- Entity Framework: Linq where clause compare date and time value with seconds difference
- Use LINQ to compare the date part of DateTime
- C# Linq compare only date from a datetime property
- How to convert date to string and compare using Linq
- How to compare date value only in LINQ
- c# Linq or code to extract groups from a single list of source data
- how to combine two columns Date and Time and compare it with given DateTime using linq
- i got this exception in .net when try to compare date in linq
- How to compare only Date portion in DateTime in LINQ to Entities (Case:- Dates are equal)
- Compare date in specific format in LINQ
- Compare a Part of the date using linq
- Convert string to int in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- How to select only the records with the highest date in LINQ
- How to compare only date components from DateTime in EF?
- Linq code to select one item
- C# Linq Where Date Between 2 Dates
More Query from same tag
- Linq: How to get second last
- Displaying List of Date-Sorted XML Elements as UI Text
- Only parameterless constructors and initializers are supported in LINQ to Entities. GeoCoordinate(latitude, longitude);
- How do I update single field value using Reflection in LINQ
- How to check if a char array contains every element in another char array?
- Linq compare datetime values
- How do I output a simple count (int) from a LINQ query?
- List.Except is not working
- XElement vs Dictionary
- Check if XElement(Record) exists?
- C# - Remove rows with the same column value from a DataTable
- c# asp.net: Cannot compare elements of type 'System.Int32'. Only primitive types, enumeration types and entity types are supported.'
- LINQ, Select only records where it reference exist in IQueryable<class> List
- Summarize hierarchical data with Linq to DB
- The entity or complex type ' ' not be constructed in a LINQ to Entities query
- Reading the dictionary element values
- EntityFramework: Retrieve data with a condition on two different context
- Generic GetTable from datacontext
- Linq Where Condtion For Different Types
- If/else selected count from sql database
- How to find string in Dictionary list and get its pair integer value
- How to rollback transaction using LINQ-to-SQL in entity framework?
- Linq query for complex type model
- Adding LINQ Where && condition in a foreach loop
- Equality for 2 lists of different types
- Searching for XElement with attribute name that contain hyphens/dashes
- Normalize xml data to object linq to xml
- combine 2 queries from the same table into one linq query
- Linq select object while changing some variables
- LINQ - Select property from object array to strongly runtime type array?