Difference between two dates

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)

10 Likes

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,

18 Likes

Good!!

Your solutions is perfect.

Thank you

3 Likes

Hi

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

5 Likes

Is it possible to calculate for months?

1 Like

Attached is the example

monthDiff.xaml (7.1 KB)

3 Likes

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.

1 Like

Hi @harjyot123,

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

Regards,
Arivu

6 Likes

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

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

1 Like

Can anyone share the syntex
if I want to use date columns itself instead of value for select query.

Also can datediff can be used in update query also.

Yes,
SELECT DATEDIFF(month, ‘2017/08/25’, ‘2011/08/25’)