Regex for date manipulation

Hi Team,

I want to extract 06 from “2023-07-06” using regex and replace it with 01.
The input will be 2023-07-06 and the output will be 2023-07-01.
The input will be 2023-07-03 and the output will be 2023-07-01.

Thanks.

@yash.choursia

System.Text.RegularExpressions.RegEx.Replace(inputDate, "-\d{2}$", "-01")

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"(?<=\d{4}-\d{2}-)\d{2}","01")

Regards,

Hey!

Try this:

System.Text.RegularExpressions.Regex.Replace(InputString,"\d{2}$","01")

Reference:

Regards,
NaNi

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