I have Data table name resultDt The datas are shown below
My requirement is to get the last 3 months count of the name.
For example NewDate = today.Addmonths(-3) it will give 03-04-17.Now the NewDate is Compare to DataTable resultDt.After the NewDate I have 3 records So it Should return Count of Rows as “3”.
Use DateTime.Compare(date1, date2) Method for this. If it returns a -ve integer, date1 is earlier than date2. If it’s a positive integer, date1 comes after date2. If it’s a 0, the dates are equal.
Try to do this yourself first. If you’re not able to do so yourself, you can come back later and attach your workflow here.
intNameCount= (From p In resultDt.Select
Where DateTime.ParseExact(p("Date").ToString,"dd/MM/yy",System.Globalization.CultureInfo.InvarientCulture)>=DateTime.Now.AddMonths(-3)
Select p).Count