Check if current date is within first to 15th of the current month

Hi All,

I need to check a date range as below:

If the current date is >=1st or <=15th of the current month

say if 3/5/2025 falls with date range
3/5/2025 >=1st and 3/5/2025 <=15 of the current month

then need to enter last month end date

else
current date

Hi @dutta.marina

Try this.

If currentDate.Day >= 1 And currentDate.Day <= 15 Then
Get the last date of the previous month
resultDate = New DateTime(currentDate.Year, currentDate.Month, 1).AddDays(-1)
Else
Use the current date
resultDate = currentDate
End If

1 Like

Hello @dutta.marina ,
please go through the below image for solution.

> New DateTime(now.Year,now.Month,1).AddDays(-1).ToString("dd-MM-yyyy")

OR YOU CAN ALSO USE BELOW LOGIC :backhand_index_pointing_down:

if(Cint(now.ToString("dd"))<=15,New DateTime(now.Year,now.Month,1).AddDays(-1).ToString("dd-MaM-yyyy"),Now.ToString("dd-MM-yyyy"))

Feel free to ask if you have further doubts,Also mark it as solution if it helps you
cheers!

1 Like

If currentDate.Day <= 15 Then
’ Get the last day of the previous month
resultDate = currentDate.AddDays(-currentDate.Day)
Else
’ Keep the current date
resultDate = currentDate
End If

1 Like

Thanks for sharing this , it worked ! :smiling_face_with_halo:

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