0

I am trying to validate date which is coming from an excel sheet , the format should be in dd/mm/yyyy i tried with regex pattern [0-9]{2}/[0-9]{2}/[0-9]{4} but this won't work with single digit date and we since we cannot add 0 at start in excel sheet this pattern ain't working. (this is for blueprism tool which have a action for regex matching]

Ankhush singh
  • 11
  • 1
  • 2

3 Answers3

2

To build in the resiliency you require, you'll have to accept either 1 or 2 digits for both dd and mm:

[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}
esqew
  • 42,425
  • 27
  • 92
  • 132
  • Hi esqew, since I am validating dates it's should not accept values greater than 31 or 12 or 30 according to months.. how can we do that? – Ankhush singh May 29 '18 at 10:19
  • @ankhush that would probably be better suited for a new, more regex-specific question, but it would probably be a duplicate of [this SO question](https://stackoverflow.com/questions/15491894/regex-to-validate-date-format-dd-mm-yyyy). – esqew May 30 '18 at 11:59
1

Since you are mentioning that you are working with BluePrism, are you sure that you really need Regex for validating dates? Because BP has built-in feature for that callable directly inside a Calc stage - checkout following example (you can see Expression of selected Calc stage in top Expression bar).

The function used for validating dates is IsDate([Some date as string]), result is saved into a Flag data-item.

enter image description here After the check you can use that Flag data-item in a Decision block and do whatever you consider appropriate if a date is not an actual date.

Note: of course, if you are working with lists/datatables in a Code stage instead of iterating over a collection in process layout, then you need something else, but this might be still helpful.

In Code stage I would probably simply use DateTime.Parse(String) method which is able to automatically convert a date in a form of a String into a DateTime object instance; example:

' DateTime.Parse throws an Exception if parsing failed.
Dim valid As Boolean = False
Try
    Dim d = DateTime.Parse(First_Date)
    valid = True
Catch e As Exception
    valid = False
End Try

See more about parsing dates using DateTime.Parse at MSDN: https://msdn.microsoft.com/en-us/library/1k1skd40(v=vs.110).aspx

There is also a nice post about parsing dates here: https://stackoverflow.com/a/18465222/7439802

0

In blue prism you can use

FormatDate(Now(), FormatOfDate)

For comparing two dates, initially Convert(" FormatDate ") in same format and then you can compare.

For " FormatDate " option you can refer Help of Blue prism and search for dateadd --> select the Calculation and decision

Vijay Dodamani
  • 264
  • 1
  • 9