DateTime.TryParseExact is giving me false

Hi,

If activity: condition => DateTime.TryParseExact(PreviousDateStr,“MM/dd/yyyy hh:mm:ss”, Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None, Nothing)
True: Assign activity: PreviousDateString = DateTime.ParseExact(PreviousDateStr,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
False: Message Box Activity: Text => “Date is in wrong format”

when i execute above workflow it’s giving false
any help will be appreciated.

Thanks
Neetha

what value you are passing in this variable

Convert.ToString(now.AddDays(-7))

Hi Neetha,

Use this:
DateTime.ParseExact(PreviousDateStr,“MM/dd/yyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)

1 Like

@neetha,

The below line of code will resolve your issue, check and let me know.

DateTime.TryParseExact(Convert.ToString(Now.AddDays(-7).ToString("MM/dd/yyyy hh:mm:ss")), "MM/dd/yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, Nothing)
4 Likes

Thanks @sarathi125 and @Rahul_Pasupuleti both for immediate response,
Below is the solution

now when i execute workflow it’s giving True

If activity: condition => DateTime.TryParseExact(PreviousDateStr, “MM/dd/yyyy HH:mm:ss”, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, Nothing)
True: Assign activity: PreviousDateString = DateTime.ParseExact(PreviousDateStr,“dd/MM/yyyy HH:mm:ss”,CultureInfo.InvariantCulture)
False: Message Box Activity: Text => “Date is in wrong format”

Thanks
Neetha

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