How to Subtraction DateTime Value Between two DataTable

How to Subtraction DateTime Value Between two DataTable ?
Case :
dt1 Date1 = 2019/06/04
dt2 Date2 = 2019/05/30
DateInterval = Date1-Date2

1 Like

Hi @nuttapong_ludloy

You can use time span variable
Date1.subtract date2



Do you want to substract DateTime between two dates right ?

I hope dt1 and dt2 are variable of type DateTime here. If so, then try below expression:

int days = (dt1 - dt2).Days

If the dt1 is in string type and order is mm/dd/yyyy
Datetime dtnew= CDate(dt1.toString(yyyy/mm/dd))
Is it correct???

Hi buddy @nuttapong_ludloy

If these two variables are of type string then we need o convert them to datetime first
Out_date1 = Datetime.ParseExact(Date1,“yyyy/MM/dd”,System.Globalization.CultureInfo.InvariantCulture)
Out_date2 =

Now DayInterval, a variable of type Datetime
DayInterval= Out_date2 - Out_date1

Or if they are already a Datetime Variable…
Directly like this
DayInterval = Date2 - Date1

Kindly try this and let know whether this works or not buddy
Cheers @nuttapong_ludloy