Format date from dd/mm/yyyy HH:MM AM/PM to yyyy-mm-dd

I have this date for example “01/25/2021 01:04 AM” that needs to be formatted to

2021-01-25 for end date and 2020-01-25 for start date

Here InputDate is “01/25/2021 01:04 AM”

I used below in assign activity:

End Date =Convert.ToDateTime(InputDate).ToString(“yyyy-mm-dd”)
Start Date =Convert.ToDateTime(InputDate).AddYears(-1).ToString(“yyyy-mm-dd”)

I get result as

EndDate: 2021-04-25
StartDate : 2020-04-25

This is incorrect.

Right output should be:

EndDate: 2021-01-25
StartDate : 2020-01-25

1 Like

mm means Minutes. It should be coded as "(“yyyy-MM-dd”)
For your reference


Thank you @prasath17

such a silly mistake from my side

1 Like

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