How to Subtraction DateTime Value Between two DataTable ?
Case :
dt1 Date1 = 2019/06/04
dt2 Date2 = 2019/05/30
DateInterval = Date1-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
Then
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)
Similarly
Out_date2 =
Datetime.ParseExact(Date2,“yyyy/MM/dd”,System.Globalization.CultureInfo.InvariantCulture)
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