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]
-
`{2}` means length of 2. You can use `{1,2}` to specify a length of 1 or 2. – ryantxr May 28 '18 at 16:29
-
Possible duplicate of [Regex to validate date format dd/mm/yyyy](https://stackoverflow.com/questions/15491894/regex-to-validate-date-format-dd-mm-yyyy) – Andrzej Kaczor May 29 '18 at 13:23
-
hi but this is not working with regex action in blueprism – Ankhush singh May 29 '18 at 13:46
-
It works for me, can you tell me how are you approaching the problem? In what cases it doesn't work? – Andrzej Kaczor May 30 '18 at 09:56
3 Answers
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}

- 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
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.
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

- 168
- 1
- 11
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

- 264
- 1
- 9