Hello, I am entering a date in SAP in one step. A format is requested in which the start date is the first day of the working month, the end date is +2 months and the last day of that month. The format I made adds two months but takes the day it works. I want to add +2 months and get the last day of that month. Can you help me?
for example = StartDate = 01/06/2023
end date = 31/08/2023 (last day of the month)
my codes are like this = StartDate = Datetime.now.ToString(“01.MM.yyyy”)
EndDate = Datetime.now.AddMonths(2).ToString(“dd.MM.yyyy”)
I think we misunderstood each other. It takes 01/07/2023 as the start date. For the end date, it will add two months to this date and get its last day, i.e. 31/08/202
StartDate = New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString(“dd/MM/yyyy”)
End Date
EndDate = New DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(2).Month, 1).AddDays(-1).ToString(“dd/MM/yyyy”)
Here, we are using EndDateTemp variable of DateTime type to store the next month date (from the current date), we then get the actual End Date of the month with the next Expression, by calculating the Total Days in Month.
Two expressions are used, just so we are reducing the redundant expression.