Thanks, I keep getting these error - double dayDiff = (Excel_Date - Now).TotalDays. where Excel_Date is variable which I am picking from datatable (while converting it as Convert.ToDateTime(rows(“Time of upload”).ToString)).
My problem is I want to compare if the date is a future date or not.
Hence,I have tried this solution .
i understood that Excel_date is a variable.So i am trying with different dates and it is giving me inconsistent results.
Please confirm me, if I am missing anything?
Excel_date= 12-10-2017
then it should give me difference as 0
But the result is -59
well this is due to the date format you are passing.
on your system it might be like MM/dd/yyyy(10/12/2017) better to check date format on your system write lineNow.Date.Tostring and check.
and from your excel you are getting like this 12-10-2017 i.e so format mismatching so you are getting wrong or negative result.
if you will do like this it will return you 0.
Convert.ToString((Now.Date - Now.Date).TotalDays) // write line it.
Convert.ToString((Convert.ToDateTime(“10/12/2017”)- Convert.ToDateTime(“10/12/2017”)).Days) //write line it.
this will also return you the 0 days.
Note- you were noticing why i am using .Days in the second line.
well if you will use TotalDays Extension method it will return result as a double and if you will use .Days Extension method it will return you result as an Integer.Both results will be same just the return type is different.
IMO better to use int instead of double
Thank you yes it works
I have another question,
Can you please share the program where the date which i have to compare if it is in future is in( day- Month name-year) format
e.g. 01 jan 2018
From above i have got as per my understanding that you wanna compare the future date having format like 01 jan 2018 with current date to know either it is a future date or past date.
Yes you can do this.
if your application is returning a date in a string format then you can use DateTime.ParseExact to convert first your date i.e. 01 jan 2018 to your system date format(Date.now.date).
Datetime converted_date = DateTime.ParseExact("01 jan 2018","dd MMM yyyy",Globalization.CultureInfo.InvariantCulture)
// Above will return 01/01/0001 00:00:00(MM/dd/yyyy)
and if your application system is returning already a datetime format then you just no need to convert to get date in desired format just use
Hi Short, I think you need to specify the format so it can Parse the date correctly.
Try this instead: DateTime.ParseExact(“20/10/2017”,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
Hi Guys need some help
Logic is like this
take value of current date suppose 12/18/2017 in mm/dd/yy
then take yesterday date ie . 12/17/2017
then create a string as 12/17/2017 12:00:00 12 AM;12/16/2017 12:00:00 AM
the string should include upto previous 15 dates
Please help
Hi Guys need some help
Logic is like this
take value of current date suppose 12/18/2017 in mm/dd/yy
then take yesterday date ie . 12/17/2017
then create a string as 12/17/2017 12:00:00 12 AM;12/16/2017 12:00:00 AM
the string should include upto previous 15 dates
Please help @Mr_JDavey