# Validating A Date Using Mask - Error???

**URL:** <https://techcommunity.softwareag.com/t/validating-a-date-using-mask-error/90948>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-News-and-General-Topics, Natural-on-Windows-Unix\
**Created:** [August 13, 2009, 12:09pm UTC](https://techcommunity.softwareag.com/t/validating-a-date-using-mask-error/90948 "2009-08-13T12:09:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mitchamm1](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@mitchamm1](https://techcommunity.softwareag.com/u/mitchamm1)\
**Post date:** [August 13, 2009, 12:09pm UTC](https://techcommunity.softwareag.com/t/validating-a-date-using-mask-error/90948/1 "2009-08-13T12:09:22Z")

</div>

Can anyone explain this. We have a text field, (A08), which users enter a Date in the format CCYYMMDD, eg 20090812), and validate it using MASK(20YYMMDD). If a user mistypes and enters the date as 02090812, the validation passes. Why is this?

An simple program showing this is below:  
DEFINE DATA LOCAL  
01 #A(A08) INIT \<‘02090812’\>  
END-DEFINE  
PRINT ‘=’ #A  
IF #A = MASK(20YYMMDD)  
PRINT ‘Valid’  
END-IF  
END

The above program displays the ‘Valid’ Statement when run.

The Natural version that is being used is Natural 6.1.1 Pl9.

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [August 13, 2009, 12:32pm UTC](https://techcommunity.softwareag.com/t/validating-a-date-using-mask-error/90948/2 "2009-08-13T12:32:36Z")

</div>

As stated, your mask is testing for 0 - 2 in the first position and 0 - 0 in the second position. Try ('20’YYMMDD) to see the difference.

I don’t think that either of these edit masks will get you what you want, so search these forums for previous “date mask” posts to see how to get the results that you’re looking for.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 13, 2009, 4:25pm UTC](https://techcommunity.softwareag.com/t/validating-a-date-using-mask-error/90948/3 "2009-08-13T16:25:02Z")

</div>

It’s not a good idea to combine numbers and a date-check into one mask…

See [http://tech.forums.softwareag.com/viewtopic.php?t=15585](http://tech.forums.softwareag.com/viewtopic.php?t=15585)

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [August 13, 2009, 4:54pm UTC](https://techcommunity.softwareag.com/t/validating-a-date-using-mask-error/90948/4 "2009-08-13T16:54:38Z")

</div>

Your MASK(20YYMMDD) checks for any value in the range 00-20 in the first two positions. If you just want to check for 20 in the first two positions you can either use Ralph’s suggestion of ‘20’ (which is an alpha MASK) or 20-20 (which is a numeric MASK). My preference would be for the alpha MASK.

However, if you want a range of centuries you might want to code something like 19-21 followed by YYMMDD.

WARNING; this leads to problems for century years. Here is an excerpt from Natural’s documentation:

"When dates are checked for a 2-digit year (YY), the current century will be assumed if no Sliding or Fixed Window is set. For more details about Sliding or Fixed Windows, refer to profile parameter YSLW in the Parameter Reference. "

So, if you code 19-21YYMMDD and have a date 19000229 you will be told this is valid since Natural is testing if 0229 is valid for the year 2000 (it is) rather than the year 1900 (not valid).

What is your precise validation requirement?

steve

---

<div class="post-metadata">

**Author:** ![mitchamm1](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@mitchamm1](https://techcommunity.softwareag.com/u/mitchamm1)\
**Post date:** [August 14, 2009, 2:39pm UTC](https://techcommunity.softwareag.com/t/validating-a-date-using-mask-error/90948/5 "2009-08-14T14:39:34Z")

</div>

The precise validation is that the century is the 21st century, ‘20’ so will change the validation mask to (20-20YYMMDD).

Thank you all for you help.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:57pm UTC](https://techcommunity.softwareag.com/t/validating-a-date-using-mask-error/90948/6 "2021-04-02T14:57:23Z")

</div>


