What is the code for 1st day of the last month?

What should I put for the code to become 1st day of last month ? e.g 01/07/2023
image

Hi @Muhamad_Izwan_Bin_Hamran ,

When compared with the Required Output mentioned, since Current Month is August, it looks like you would need the Previous Month 1st Day. But do remember that 1st is always 1. So we can use it in the formatting :

DateTime.Now.AddMonths(-1).ToString("01/MM/yyyy")

For the Current Month :

DateTime.Now.ToString("01/MM/yyyy")
1 Like

@Muhamad_Izwan_Bin_Hamran

new DateTime(Now.Year,Now.Month,1).AddMonths(-1).ToString(“dd/MM/yyyy”)

output= “01/07/2023”

datetime.now.addmonths(-1).tostring(“MMM-yy”) gives like Jul-23

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