1/1/2022-1/20/2022 the output should be 20
If I find using differ count i am getting as 19
Hi @sruthesanju
I think the output 19 is correct.
If you see the below image Date 2 is just started. So, until Date 2 is fully completed the duration will remain as 19 days
In the below image Date 2 is almost ended but still 1 second remaining. So, until Date 2 is fully completed the duration remain as 19 days
In the below image Date 2 is completed and next day started. So, the duration now is 20 days
If you want 20 days as an output then please add +1 days to your Date 2
DateTime.ParseExact(“01/20/2022”,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).AddDays(1)
Thanks
John
From 1-20 if we count means it’s 20 days right there will be no time given only date is there
Normal Integer calculation and Date Time calculation are bit different.
For all types of DateTime operation using CDate , Convert.ToDateTime, DateTime.Parse, DateTime.ParseExact you need to specify the time.
When you don’t give time parameter, “00:00:00” will be added by default.
because of this behavior its always calculated as start datetime to end datetime not the start date to end date
You can use the attached workflow for your date calculation, and it will give your desired results
Date_Calculator.xaml (7.5 KB)
Can you share photo of code i am unable to open it
You can Implement this Date calculation using below code
Approach 1: CDate
(CDate(in_date_2).AddDays(1)-CDate(in_date_1)).Days
Approach 2: DateTime.Parse
DateTime.Parse(in_date_2).AddDays(1).Subtract(DateTime.Parse(in_date_1)).Days