# Date validation

**URL:** <https://clarionhub.com/t/date-validation/3395>\
**Category:** questions\
**Tags:** language\
**Created:** [June 26, 2020, 12:21pm UTC](https://clarionhub.com/t/date-validation/3395 "2020-06-26T12:21:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [June 26, 2020, 12:21pm UTC](https://clarionhub.com/t/date-validation/3395/1 "2020-06-26T12:21:05Z")

</div>

I have a string entry field (**string (100)** and @s100 fromat) and a user can input any date there. I need to validate if the entered value is a valid clarion date, let say, in @d6 format. Is it possible to check it easy?

For example:  
1a/12/2020 **false**  
11/2020 **false**  
26/06/2020 **true**

---

<div class="post-metadata">

**Author:** ![totalhip](https://clarionhub.com/user_avatar/clarionhub.com/totalhip/32/1477_2.png) [@totalhip](https://clarionhub.com/u/totalhip)\
**Post date:** [June 26, 2020, 12:32pm UTC](https://clarionhub.com/t/date-validation/3395/2 "2020-06-26T12:32:19Z")

</div>

Might a Windows short date @d17 help?

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [June 26, 2020, 12:35pm UTC](https://clarionhub.com/t/date-validation/3395/3 "2020-06-26T12:35:09Z")

</div>

how it can help???..

---

<div class="post-metadata">

**Author:** ![MarkGoldberg](https://clarionhub.com/user_avatar/clarionhub.com/markgoldberg/32/1511_2.png) [@MarkGoldberg](https://clarionhub.com/u/MarkGoldberg)\
**Post date:** [June 26, 2020, 12:40pm UTC](https://clarionhub.com/t/date-validation/3395/4 "2020-06-26T12:40:04Z")

</div>

Can you simply put a date picture on the field, but remove the ,MASK attribute  
IIRC, that way they can enter the date in any format, and it’s converted to the formatted picture

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [June 26, 2020, 12:45pm UTC](https://clarionhub.com/t/date-validation/3395/5 "2020-06-26T12:45:06Z")

</div>

Mark, but user can also input just a normal string in this field as well and I need to validate if it is DATE or just normal string. If it looks like date (so that I need to validate) - then OK, if it normal string - OK.

---

<div class="post-metadata">

**Author:** ![totalhip](https://clarionhub.com/user_avatar/clarionhub.com/totalhip/32/1477_2.png) [@totalhip](https://clarionhub.com/u/totalhip)\
**Post date:** [June 26, 2020, 12:53pm UTC](https://clarionhub.com/t/date-validation/3395/6 "2020-06-26T12:53:34Z")

</div>

Use a local date variable to allow date input. Use your string variable for string input.  
Resolve final string value prior to saving record.

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [June 26, 2020, 12:56pm UTC](https://clarionhub.com/t/date-validation/3395/7 "2020-06-26T12:56:13Z")

</div>

not sure I understand your idea. I have ONE variable (string) and one Entry control. This is string entry control - users can type whatever they want. All I need to be able to check (validate) if entered info is a DATE

---

<div class="post-metadata">

**Author:** ![MarkGoldberg](https://clarionhub.com/user_avatar/clarionhub.com/markgoldberg/32/1511_2.png) [@MarkGoldberg](https://clarionhub.com/u/MarkGoldberg)\
**Post date:** [June 26, 2020, 12:58pm UTC](https://clarionhub.com/t/date-validation/3395/8 "2020-06-26T12:58:09Z")

</div>

Maybe try this:  
add a hidden control with a Date picture and no mask  
then push the string value into the control  
possibly use PRESS(String)

then check the USE variable of the hidden control  
if it’s non-zero then it must be a valid date

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [June 26, 2020, 1:05pm UTC](https://clarionhub.com/t/date-validation/3395/9 "2020-06-26T13:05:41Z")

</div>

Mark, it’s not just screen inputting. I need common function like

CheckDate(my:string) that just check and return False or True

---

<div class="post-metadata">

**Author:** ![MarkGoldberg](https://clarionhub.com/user_avatar/clarionhub.com/markgoldberg/32/1511_2.png) [@MarkGoldberg](https://clarionhub.com/u/MarkGoldberg)\
**Post date:** [June 26, 2020, 1:08pm UTC](https://clarionhub.com/t/date-validation/3395/10 "2020-06-26T13:08:27Z")

</div>

So, write the method, and add a window in the method  
Granted it’s not terribly efficient, but it’s a place to start  
Clearly the RTL has the functionality built-in somewhere.

A different approach could be to try to parse the string into a date

or DEFORMAT it with every date picture you can think of  
trying to find one that returns non-zero

---

<div class="post-metadata">

**Author:** ![totalhip](https://clarionhub.com/user_avatar/clarionhub.com/totalhip/32/1477_2.png) [@totalhip](https://clarionhub.com/u/totalhip)\
**Post date:** [June 26, 2020, 1:09pm UTC](https://clarionhub.com/t/date-validation/3395/11 "2020-06-26T13:09:38Z")

</div>

Perhaps the entry can be more structured?  
The user can set a check to indicate a date will be entered – or not set to indicate a string will be entered. You then set the control accordingly.  
Allowing dates to be validated with a control is going to be easier than doing it on your own.

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [June 26, 2020, 1:09pm UTC](https://clarionhub.com/t/date-validation/3395/12 "2020-06-26T13:09:41Z")

</div>

Mark, yes, I was thinking about parsing…

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [June 26, 2020, 1:11pm UTC](https://clarionhub.com/t/date-validation/3395/13 "2020-06-26T13:11:04Z")

</div>

Douglas, it’s better to have some common function

---

<div class="post-metadata">

**Author:** ![MarkGoldberg](https://clarionhub.com/user_avatar/clarionhub.com/markgoldberg/32/1511_2.png) [@MarkGoldberg](https://clarionhub.com/u/MarkGoldberg)\
**Post date:** [June 26, 2020, 1:17pm UTC](https://clarionhub.com/t/date-validation/3395/14 "2020-06-26T13:17:21Z")

</div>

The following appears in String Theory 3 (and likely older versions too)

> !------------------------------------------------------------------------------  
> ! works hard to figure out what the date is from the input.  
> ! simple numbers \> 2100 are assumed to be deformatted already, and returned as-is.  
> StringDeformat.DeformatDate PROCEDURE (String pValue,)

It returns a REAL

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [June 26, 2020, 1:18pm UTC](https://clarionhub.com/t/date-validation/3395/15 "2020-06-26T13:18:14Z")

</div>

Mark, nice, I have ST so going to check it…

hmmm… have 2.63 version. And it has no such method… can’t upgrade

---

<div class="post-metadata">

**Author:** ![totalhip](https://clarionhub.com/user_avatar/clarionhub.com/totalhip/32/1477_2.png) [@totalhip](https://clarionhub.com/u/totalhip)\
**Post date:** [June 26, 2020, 2:06pm UTC](https://clarionhub.com/t/date-validation/3395/16 "2020-06-26T14:06:37Z")

</div>

As you please. Something else to consider 26 June 20 and July 1, 2020.

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [June 26, 2020, 5:12pm UTC](https://clarionhub.com/t/date-validation/3395/17 "2020-06-26T17:12:44Z")

</div>

Is PRESS() a viable option nowadays?

---

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [June 26, 2020, 6:21pm UTC](https://clarionhub.com/t/date-validation/3395/18 "2020-06-26T18:21:55Z")

</div>

So you wrote a function but it doesn’t work as expected, right?

---

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [June 26, 2020, 7:32pm UTC](https://clarionhub.com/t/date-validation/3395/19 "2020-06-26T19:32:50Z")

</div>

Hidden ENTRY with date picture @d05 will convert string ‘1a/12/2020’ to date 01/01/2002 which is valid but not expected result.

---

<div class="post-metadata">

**Author:** ![vitesse](https://clarionhub.com/user_avatar/clarionhub.com/vitesse/32/837_2.png) [@vitesse](https://clarionhub.com/u/vitesse)\
**Post date:** [July 3, 2020, 8:00am UTC](https://clarionhub.com/t/date-validation/3395/20 "2020-07-03T08:00:26Z")

</div>

Hi Clarion\_clarion (maybe change that to your real name so we know who we are talking to!)

so let’s see

- you want to see if the date is a valid date in @d6 format

- you have StringTheory 2 but not ST3 and can’t update… (BTW I see the upgrade is only $39 and has many new methods, optimizations and bug fixes so seems like a no brainer to me!)

- you a want a function where you pass a string and get back true for a valid date otherwise false

@d6 has the format dd/mm/yyyy so off the top of my head I would do something like:

```
CheckDate procedure (String pStr)

st stringTheory
dd long,auto
mm long,auto
yyyy long,auto

  code
  st.setValue(pStr)
  st.trim()
  if ~st.isAll('/0123456789') then return false. ! contains invalid characters

  st.split('/')
  if st.records() <> 3 then return false. 

  dd = st.getLine(1)
  if dd < 1 or dd > 31 then return false.

  mm = st.getLine(2)
  if mm < 1 or mm > 12 then return false.
  if dd = 31 and inlist(mm,2,4,6,9,11) then return false.

  yyyy = st.getLine(3)
  if ~yyyy then return false.

  ! note: you may wish to allow a 2 digit year and 
  ! guess the century, for example:
  if yyyy < 25
    yyyy += 2000
  elsif yyyy < 100
    yyyy += 1900
  end

  ! you may wish to do range checks on year here...
  ! for example:
  if yyyy < 1800 or yyyy > 2100 then return false.
  
  if mm <> 2 or dd < 29 then return true. ! valid date...

  ! special tests for February
  if dd = 30 then return false.
  
  ! dd is 29 so check for leap year
  if yyyy%4 then return false.
  if yyyy%100 then return true.
  if yyyy%400 then return false.

  return true

```

well I wouldn’t quite do that - inlist() is very expensive and so I probably would use case instead but this keeps it on one line…hope that helps

Geoff R

[Next page](https://clarionhub.com/t/date-validation/3395.md?page=2)
