Difference between two dates


#1

Hello everybody!!

somebody help me to determinate how can I get the difference between two dates?

For example (yyyy-MM-dd):
Date1= 2016-01-30
Date2=2016-02-01

The result will be 2 ( two days is the interval between that dates)


#2

Hello!

You can use the DateDiff function.

Example:

Syntax: DateDiff(DateInterval, Date1,Date2)
Code: DateDiff(DateInterval.Day, “2016-01-30”,“2016-01-30”)

It will return the number of the days between the two dates as Integer Type.

Hope It helps!

Regards,


#3

Good!!

Your solutions is perfect.

Thank you


#4

Hi

You can also use like this
Date2.Subtract(date1)


#5

Is it possible to calculate for months?


#6

Attached is the example

monthDiff.xaml (7.1 KB)


#7

can someone help me to calculate date diff between date format in “11-Apr-2018” and today(). I want to find out if this date is 4 weeks old or not.


#8

Hi @harjyot123,

Try this code
DateDiff(DateInterval.Day,DateTime.ParseExact(str_Date, "dd-MMM-yyyy", CultureInfo.InvariantCulture),DateTime.now())

Regards,
Arivu


#9

It gives me an error saying culture info is not declared. I also imported “System.globalization”.


#10

DateDiff(DateInterval.Day,DateTime.ParseExact(str_Date, "dd-MMM-yyyy", System.Globalization.CultureInfo.InvariantCulture),DateTime.now())