Hi. I am trying to subtract the days between two strings that has the format of dd/MM/yyyy in both variables. Both variables types are String. I have tried assigning a new variable under the type of Int32 with DateDiff(DateInterval.Day, Date1, Date2) and it returned the error
An example
Date1 = 10/02/2021
Date2 = 22/12/2020
What is the best way to go forward in order to get the number of days subtracted between the two dates strings?
Hi, thank you for the above links. I tried these (the dates are in a variable so is not hardcoded as shown in the above links) and no joy as it keeps giving the same error message as shown in the screen shot of original post. Any idea where I may be going wrong?
For the NowDate variable, the value stored is as Date.Now.addDays(-14).toString(“dd/MM/yyyy”) as I need the date from 14 days prior to today
For the RequestDateCreated is extracted from a table where the value will then be like “18/11/2020 16:19:03”
and to get the date only the value is outputted to System.Text.RegularExpressions.Regex.Matches(CreatedRequestDate,“\d{2}/\d{2}/\d{4}”)(0).toString where it will output the value “18/11/2020” then
you are getting this error because the date format of date in variable is dd/MM/yyyy and your system date format is different (might be MM/dd/yyyy). When we use CDate(), it uses system date format as reference to convert the string to date. When function tried to convert “27/01/2021” string to date, it tried to convert “27” as month which is invalid month hence error.