Fixed date


I use to variables:

dateAudytStart (DateTime), default: New DateTime(Now.AddMonths(-12).Year,Now.AddMonths(-12).Month,1)


dateAudytEnd (DateTime), default: New New DateTime(Now.Year,Now.Month,1).AddDays(-1)

These dates are right, when I want to start UiPath audit e.g. for April at the end of May.
If I would like to start on the beginning of the next month (June), I have to change default:
start: New DateTime(Now.AddMonths(-12).Year,Now.AddMonths(-13).Month,1)
end: New DateTime(Now.AddMonths(-1).Year,Now.AddMonths(-1).Month,1).AddDays(-1)

to receive the same result (start: 2019-05-01 and end: 2019-04-30 - 12 previous month).

Generally I do audyt for April from about 2019-05-26 to 2019-06-10.

How I would like to create fixed variables, which give me the same result (when I start my audit 2019-05-28 or 2019-06-05.

Any ideas?


For Start, set current year into a var & minus 1. Then hardcode your datetime.
For end, set your current year into a var. Then hardcode your datetime.

I do not understand. If I run UiPath 28.05.2019 or 06.05.2019 I need to receive the same result - start date 2018.05.01 and end date 2019.04.30.

The same one month later. - runing at the end of June, or on the begining of July, the result shoud be 2018.06.01 and 2019.05.31.

I hope that it is clear.

Hi @Krzysztof,

you can use variable with values mentioned below to get your workdone.

Start = now.AddYears(-1).AddDays(Day(DateSerial(now.AddYears(-1).Year, now.AddYears(-1).Month + 1, 0))-Now.Day)

end = now.AddMonths(-1).AddDays(Day(DateSerial(now.Year, now.Month + 1, 0))-Now.Day)

Shiva Karthik


start date gives 2018-06-30 (today should 2018-05-01)
end date gives 2019-05-30 (should 2019-04-30)

Generally to get perdiod in format yyyy-MM I use Now.AddDays(-50).ToString(“yyyy-MM”)
I subtract 50 days to get the same value, independently I run UiPath at the end of month, or on the begining.

Unfortunately I have problem with date in format yyyy-MM-dd (If I subtract 50 days, I have wrong result in day - year and month is ok).

hi @Krzysztof,

You can use the above statements to get the dates and implement some additional logic to decide what should happen at the end of month or starting of month.

“Start :”+now.AddYears(-1).AddMonths(-1).AddDays(-(now.Day-1)).ToString+“end :”+now.AddMonths(-2).AddDays(Day(DateSerial(now.Year, now.AddMonths(-1).Month + 1, 0))-Now.Day).ToString

Shiva Karthik

Still error:
Start = now.AddYears(-1).AddDays(Day(DateSerial(now.AddYears(-1).Year, now.AddYears(-1).Month + 1, 0))-Now.Day) gives 2018-06-30 (should 2018-05-01),
end = now.AddMonths(-1).AddDays(Day(DateSerial(now.Year, now.Month + 1, 0))-Now.Day) gives 2019-05-30

In my opinion I should substract 50 days, but I do not how to do to receive:
start - day “01”
end - last day of the month

Hi @Krzysztof

use below command

"Start Date: “+now.AddDays(-(now.Day-1)).AddYears(-1).ToString(“dd.MM.yyyy”)+” End Date: "+ now.AddDays(-now.Day).ToString(“dd.MM.yyyy”)

it help u

Mayby another way:
in period from 25.05.2019-10.06.2019 (these days I run Uipath) I need to receive
start date 2018-05-01
end date 2019-04-30

in period from 25.06.2019-10.07.2019
start 2018-06-01
end 2019-05-31

in period 25.07.2019-10.08.2019
start 2018-07-01
end 2019-06-30


Hi @Krzysztof

"Start Date: “+now.AddDays(If(now.Day>10,now.Day-1,-(now.Day-1+datetime.DaysInMonth(now.Year,now.Month-1)))).AddYears(-1).ToString(“yyyy-MM-dd”)+” End Date: "+now.AddDays(If(now.Day>10,now.Day,-(now.Day+datetime.DaysInMonth(now.Year,now.Month-1)))).ToString(“yyyy-MM-dd”)

tried this. it suit ur requirement

Please let me know to which day I receive date 2018-05-01 and 2019-04-30? To 2019-06-10?


yes u will receive “2018-05-01 and 2019-04-30” dates until 2019-06-10 this date

Ok. And from 2019-06-11 to 2019-07-10 I will receive 2018-06-01 and 2019-05-31?

yes correct … u can able to check,
to change System time

go to Date and time setting in ur pc change the system time…


It is strange:
present date 2019-06-11
results 2018-06-21 and 2019-06-22

present date 2019-06-27
results 2018-07-23 and 2019-07-24

present date 2019-07-15
results 2018-07-29 and 2019-07-30

Mayby there is something with date and time setting

yes forget to add minus

use below
"Start Date: “+now.AddDays(If(now.Day>10,-(now.Day+1),-(now.Day-1+datetime.DaysInMonth(now.Year,now.Month-1)))).AddYears(-1).ToString(“yyyy-MM-dd”)+” End Date: "+now.AddDays(If(now.Day>10,-(now.Day),-(now.Day+datetime.DaysInMonth(now.Year,now.Month-1)))).ToString(“yyyy-MM-dd”)

check and let me know

End date is ok, start - not.

Start date is correct when the period is from 1st do 10th of the month.
It the date is later, eg. 30.06.2019, I received 2018-05-30, instead 2018-06-01.
If my present date is 11.07.2019, I got 2018-06-29 instead 2018-07-01

Hello @Krzysztof
give below a try

DateTime ddate = CDate("11Jun2019") >> you can set any date you want...

ddate = if(Cint(ddate.ToString("dd"))>10,ddate,ddate.AddMonths(-1))

Log message: "StartDate: " & CDate("01" & ddate.AddYears(-1).ToString("MMM yyyy")).ToString("ddMMMyyyy")

Log message: "EndDate: " & CDate(Date.DaysInMonth(ddate.AddMonths(-1).Year,ddate.AddMonths(-1).Month) & ddate.AddMonths(-1).ToString("MMM yyyy")).ToString("ddMMMyyyy")

yes yes everytime i miss small thing

ha ha now miss (-) symbol

use this
"Start Date: “+now.AddDays(If(now.Day>10,-(now.Day-1),-(now.Day-1+datetime.DaysInMonth(now.Year,now.Month-1)))).AddYears(-1).ToString(“yyyy-MM-dd”)+” End Date: "+now.AddDays(If(now.Day>10,-(now.Day),-(now.Day+datetime.DaysInMonth(now.Year,now.Month-1)))).ToString(“yyyy-MM-dd”)

It works!
Thanks a lot!!!