Changing date variable

Hi,

I have below format of date:

now.AddDays(If(now.Day>10,datetime.DaysInMonth(now.Year,now.Month-1)-now.Day,-now.Day)).AddYears(-1).ToString(“yyyy-MM-dd”)

I should get:
from 11.05.2019-10.06.2019: 2018-05-31 - it is right
from 11.06.2019-10.07.2019: 2018-06-30 - I got 2018-07-01

How to change above format to get right value?

Buddy may i know the conditions that you want to apply here so that we can try to form a expression that satisfies your condition
Cheers @Krzysztof

Hi @Krzysztof

forget to add minus one

use below code

now.AddDays(If(now.Day>10,datetime.DaysInMonth(now.Year,now.Month-1)-now.Day-1,-now.Day-1)).AddYears(-1).ToString(“yyyy-MM-dd”)

Regards
Amaresan.P

If I change system date on 2019-06-10, I receive 2018-05-30.
If system date is 2019-05-07, I have 2018-04-29. The wrong is -1 day.

@Krzysztof i add 1 is only true condition

but how it add false condition also? ok any way remove 1 in false condition

use below

now.AddDays(If(now.Day>10,datetime.DaysInMonth(now.Year,now.Month-1)-now.Day-1,-now.Day)).AddYears(-1).ToString(“yyyy-MM-dd”)

I would like to receive:
system date from 2019-05-11 to 2019-06-10 - result 2018-05-31
system date from 2019-06-11 to 2019-07-10 - result 2018-06-30
etc.

As I see there is mistake, when system date is betwen 11-31 of the month.
When the period is from 1 to 10, result is ok.

Eg.

System date: 2019-07-16 - should be 2018-07-31, is 2018-07-29
System date: 2019-08-14 - should be 2018-08-31, is 2018-08-30
But when system date is today (2019-06-11), result is ok (2018-06-30).

Mayby the problem is when the month is longer than 30 days.

@Krzysztof

yes your right… i supposed to calculated current month instead of pre Month

try this
now.AddDays(If(now.Day>10,datetime.DaysInMonth(now.Year,now.Month)-now.Day,-now.Day)).AddYears(-1).ToString(“yyyy-MM-dd”)

It is not correct now, becouse when I add counter of the months (11), I will get 2019-05-30 (instead 2019-05-31).

@Krzysztof

i did’t get you … can you explain

2019-05-30 or 2019-05-31 it supposed be 2018 right

did use latest code which is shared by me right?

To this date I add counter of the months to get next month:
now.AddDays(If(now.Day>10,datetime.DaysInMonth(now.Year,now.Month)-now.Day,-now.Day)).AddYears(-1).*AddMonths(intCounter).*ToString(“yyyy-MM-dd”)
I should receive last day next month:
eg. default counter is 0 - result is 2018-06-30
increase of the counter +1 - result should be 2018-07-31
next increase +1 - result 2018-08-31
etc.
When I add 11, the result is 2019-05-30.

@Krzysztof

Add Months always increase 30 day only

@Krzysztof

if you want month end do like this.

1.assign a variable for current date
inside foreach
2.replace all now with current date variable
3.put assign current date variable.addmonth(intcounter)