How to use the last day of last month, but only for the first 10 days of current month

Hello, I am looking for a workaround for an issue we have with our robot right now.
To fill in the current date in our ERP system we use the expression: System.DateTime.Now.ToString(“dd/MM/yyyy”)

But for the first 10 days of the current month we don’t want to use the current date. But the last day of last month (today is 2 july, but we want 30 june) . So it will look something like:
If “dd” =< “10” then "System.DateTime.Now.ToString(“dd/MM/yyyy”) -“dd”
if “dd” > “10” then "System.DateTime.Now.ToString(“dd/MM/yyyy”)

I have no idea if this is possible in UiPath or how I can do this. I would love to get some help with this

1 Like

if cint(now.ToString(“dd”))<=10
now.AddDays(-cint(now.ToString(“dd”))).ToString(“dd-MM-yyyy”) -> this gets you the last day of the previous month


it is definitely possible, your logic is pretty much there.

Just use IF <= 10 THEN


Hey @Peter_Peter,

Welcome to the UiPath community !!!.
Please use the code below:

If Convert.ToInt32(“dd”))<=10“dd”)))


Hi Buddy @Peter_Peter

Welcome to uipath community and thats a good question to start with
yes of course you were almost done the condition is correct just we need to make some small changes
I hope you mean like if the current date is less than 10 th of a month then we need the last day of previous month or if the current date is more than 10th of a month then we can have the current date itself
–use a assign activity like this
in_date = Convert.ToInt32(Datetime.Now.ToString(“dd”))
where in_date is a variable of type int32
–then use a if condition like
in_date < 10
if this condition gets passed it will go to THEN part where can put like this to get the last day of previous month
out_date_value = Now.AddMonths(-(Convert.ToInt32(Datetime.Now.ToString(“dd”)))).ToString("dd/MM/yyyy)
where out_date_value is a variable of type string
or if the above condition fails it will go to ELSE part where we can mention like this
out_date_value = Now.ToString(“dd/MM/yyyy”)

Thats all buddy you are done
Hope this would help you
Cheers @Peter_Peter


Thanks guys, I got it to work using this solution. I now understand better how the coding works!
For your “then” code, I changed Now.AddMonths to Now.AddDays like Amarasto has said!

1 Like

Cheers @Peter_Peter