Date is showing incorrect. Please suggest the solution

Hi,
I had tried below format and date is displaying in incorrect format.
DateTime.Today.AddDays(-9).ToString(“MM/dd/yyyy”)
DateTime.Now.AddDays(-9).ToString(“MM/dd/yyyy”)

Correct date is should be 05/10/2023 and it showing 05/01/2023

Hi @Puneet_Singh ,

I believe it is the right format as you have used MM/dd/yyyy, MM - Month, dd - Day, yyyy-Year

I know format is correct but still it showing incorrect date

Hi @Puneet_Singh

Can you try this-

DateTime.Today.AddDays(-9).ToString(“MM/dd/yyyy”, CultureInfo.InvariantCulture)

Thanks!!

@Puneet_Singh

Now the date is 10th and you added AddDays(-9) which is 01 which is correct

Thanks,
Srini

@Puneet_Singh ,

Could you let us know what should be the Correct Date value according to you ?

@Puneet_Singh

If you want the current date

Then you have to remove the .AddDays(-9)

Thanks,
Srini

If you just want today, you use

Now.ToString(“MM/dd/yyyy”)

The AddDays method is to do exactly that - add (or subtract) days from a date.

Looks like you’re nesting a lot of IFs. That’s poor design, it’ll get confusing and repetitive. You should use the Else If activity instead.

Sorry guys my Bad…

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