Date Time issue geting number of days using substraction

I have string
str_Date =“1/23/2024 2:02:59”
want same in date_Date variable in formal “MM/dd/yyyy” in datatime variable type.

then want to subtract so that I will get value
NumOfDays =Current Date - date_Date

I need NumberOfDays in interger type.

Can you please help me .

Hi @Aditi0374

str_Date ="1/23/2024 2:02:59"
date_Date = DateTime.ParseExact(str_Date, "M/d/yyyy h:mm:ss", System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")
Messge Box (DateTime.Now - DateTime.Parse(date_Date)).Days

Hi @Aditi0374

If you want to get the number of days between str_Date and Today’s date.

Check the below expression,

- Assign -> NumofDays = (DateTime.Now-CDate(str_Date)).days

Check the below workflow for better understanding,

No need to create another date_Date datetime variable to convert the str_Date to DateTime format. Directly use the CDate to convert.

Hope it helps!!

Hi @Aditi0374 ,

To achieve this in UiPath, you can follow these steps:

  1. Assign Activity: To convert str_Date to a DateTime variable date_Date.

    date_Date = DateTime.ParseExact(str_Date, "M/dd/yyyy h:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
    
  2. Assign Activity: To calculate the number of days difference and Save to an Integer.

    NumOfDays = CInt((DateTime.Now - date_Date).TotalDays)