I want to add random 1-4 days to the existing dates from excel

Hi All,

  1. I have a date column in the excel which is in the format “02/07/2022 22:26:22”.

  2. Currently i used the logic which adds 7 days for all the existing dates.
    LOGIC : Date.Parse(datetime).AddDays(7).toString(“MM/dd/yyyy HH:mm:ss”)
    datetime is the Variable.

  3. But I want to add random 1 - 4 days for each row which consists of 950 records.

Please help.

HI @shruthi_arali

Can you explain why are you adding 1-4 days any condition like this?

Regards
Gokul

@Gokul001

  1. I have a column called “Opened at” in excel.
  2. I have filed in one of the web application called “Resolved at”.
  3. for each row from the excel , the date should increase between 1 - 4 days and type into the field “Resolved at”

Attached screenshot
Opened at
Resolved at

Hi @shruthi_arali ,

We can use a Random Type variable to do your Randomisation of the number of days.

Create a System.Random type variable, say rndVar

Initialise it using an Assign like below :

rndVar = new Random

Next in place of 7, we can call the Random function in the below way :

Date.Parse(datetime).AddDays(rndVar.Next(0,5)).toString(“MM/dd/yyyy HH:mm:ss”)

rndVar.Next(0,5) is used to get a Random number between 0 and 5

1 Like

Hi @shruthi_arali and @supermanPunch ,

Do give @supermanPunch 's brilliant solution a try, but you might want to tweak it a little like so →

Date.Parse(datetime).AddDays(New Random().Next(1,5)).toString(“MM/dd/yyyy HH:mm:ss”)

you have to start from 1 or else it will return zero.

image

Also, it isn’t necessary to initialize it in a separate Assign Activity, you can directly do so in the snippet of code.

Kind Regards,
Ashwin A.K

@ashwin.ashok and @supermanPunch

I tried the logic recommended and Its working for me…

Thank you so much :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.