How to use DateTime.TryParse()

Hi guys,

I’m using DateTime.TryParse(in_Date, CalendarDate) to check whether the value and the format of in_Date is correct.

The above Data type are:
1.in_Date(String)
2.CalendarDate(DateTime)

If I understand correctly, It supposed to pass the converted data from in_Date to CalendarDate if the return result if true

The return result I got is true, but it didn’t pass the Converted Date to CalendarDate

The given value of in_Date is 4/5/2020,
but the return result of CalendarDate is 1 for Year, Month and Day.(00010101(yyyyMMdd))

Thanks for any advice.

Hi,

If you use Assign activity, it does not support ref type argument.
So, can you try Invoke Method activity?

Regards,

2 Likes

@opas1216, Please refer below link to get more detail around DateTime.TryParse:

Cheers

@opas1216 - you can use the regular expression to validate the date…

you can use below expression to verify/validate the date string. based on match status - you can use CDate(in_Date.ToString) to convert to a date.

^(?:(?:31(/|-|.)(?:0?[13578]|1[02]|(?:Jan|Mar|May|Jul|Aug|Oct|Dec)))\1|(?:(?:29|30)(/|-|.)(?:0?[1,3-9]|1[0-2]|(?:Jan|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(/|-|.)(?:0?2|(?:Feb))\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(/|-|.)(?:(?:0?[1-9]|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep))|(?:1[0-2]|(?:Oct|Nov|Dec)))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$

1 Like

Hi @Yoichi
Yes, I did use the Assign Activity, I thought it support ref type.
Is that means, normally it should support ref type, but however it didn’t?

Thanks for you help, I’ll try it later.

Hi @GBK

Thanks for you reply.

I also tried using regex like you said.

I 'll try your way later, but it need some time to let me understand your method. :sweat_smile:
your expression is more complex than mine.

I just used like “[0-9{1,2}/[0-9{1,2}/[0-9{4}]” to match for example like 2020/04/08…etc.
Could you explain more detail what targets are your regular expression matching?

Thanks you again for your help and sharing. :slight_smile:

@opas1216 - Its a combination of date formats along with leap year check as well.
You can try and let us know if you need further help…