score:1
Can this link help you?
where t.CreateDate.Date < DateTime.Today.AddMonths(-1)
score:0
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"));
score:2
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
Source: stackoverflow.com
Related Articles
- 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
- Select a row only if a field from previous row is less from a field in the active row
- What advantages and drawbacks does Enumerable.SequenceEqual(list1, list2) has against list1.All(list2.Contains)?
- System.Linq.Dynamic.Core - querying nested objects
- Xdocument amend all attributes that match
- Sort array on one variable that can hold multiple values
- Linq- Issue in custom order by
- Recursively iterate through subdirectories and add directory to a list, if it contains any file with a specific ending
- Linq Join datatables on multiple columns
- How can I SELECT record from database WHERE a number is CLOSEST to one I supply?
- Linq: DataTable to List. Cast issue
- Which LinQ syntax?
- Getting values from xelement
- Linq - Get the Static class constants as List
- Condition inside a Lambda Expression
- Is it the same to iterate over Linq expression result than to assign it first to a variable?
- Trying to retrieve data from multiple related tables in mysql from very big data
- Linq making very inefficient Entity Framework query
- returning multiple column and sum using linq expression
- Using LINQ to XML, how can I join two sets of data based on ordinal position?
- Convert datetime2 to string("dd/MM/yyyy") in LINQ