I have one date string aa=2023-01-03, I need this date adjust one month before, EG. bb=2022-12-03, I use bb=string.Format(Cdate(aa).AddMonths(-1).ToShortDateString,“yyyy-MM-dd”), however, I get 2022/12/03, in fact , i need it’s value is 2022-12-03, who can help me, thanks.
Hi @Lori ,
Is this what you meant?
CDate("2023-01-03").AddMonths(-1).ToString("yyyy-MM-dd")
I think the issue is with using ToShortDateString.
Kind Regards,
Ashwin A.K
HI @Lori
You can dive the date formats in the array of strings in the below expression.
DateTime.ParseExact(aa,{"yyyy-MM-dd","yyyy/MM/dd"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("yyyy-MM-dd")
You just need to add the formats in the array if in case any other formats
Regards
Sudharsan
@Anil_G @ashwin.ashok @Sudharsan_Ka
Thanks for your great help, Anil_G is the first, so I make Anil_G method as solution.
1 Like
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.