How know 1st & 2nd of Month?

Hello all,

Normally from date (-2) to currently day
DateTime.Now.AddDays(-2).ToString(“dd/MM/yyyy”)
DateTime.Now.ToString(“dd/MM/yyyy”)
image

But if 1st, 2nd day of Month it will error how know today is 1st day, 2nd of Month ?. Thank you
Ex:

June 1: From 01/06/2022 (-0day) to 01/06/2022

June 2: From 02/06/2022 (-0day) to 02/06/2022

June 3: 01/06/2022 (-2day) to 03/06/2022
June 4: 02/06/2022 (-2day) to 04/06/2022

DateTime.Now.Day = 1 or DateTime.Now.Day = 2
image

1 Like

Hi,

FYI, another approach:

The following expression helps you.

DateTime.Now.AddDays(2*CInt(Now.Day>2)).ToString("dd/MM/yyyy")

Regards,

1 Like

Thank you so fast, i want ask more
Normally from -1day to -1day

DateTime.Now.AddDays(-1).ToString(“dd/MM/yyyy”)

image

If today June 01 how it change 31/05/2022 - 31/05/2022

Thanks

if today is jun01, just do this
DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy")

it will return 31/05/2022

1 Like

oh need check here. Thank you

image

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