‎2009 Jan 21 3:58 PM
My date is like yyyy-mm-dd or dd-mm-yyyy and I need a validation. Date will be reading from flat file. I need the code just for date validation.
I want to check if the first variable is 2 or 4 characters long. If it is 4, itu2019s a year and the date format would be YYYY-MM-DD.
If it is 2, itu2019s a day or month the format would be DD-MM-YYYY or MM-DD-YYYY.
If I can distinguish each variables date, month & year, I can get the output the way I want with concatenate.
Need coding and appreciate your help.
‎2009 Jan 21 4:21 PM
I think the simpliest way is, if you just simply check is the third character is '-' or not:
IF date+2(1) EQ '-'.
==> date has DD-MM-YYYY format
ELSE.
==> date has YYYY-MM-DD format
ENDIF.
‎2009 Jan 21 4:10 PM
HI mau
I think you should check the pattern not the 2 or 4 characters
use if date CP '+++--+' then its YYYY-MM-DD format
if date CP '+--+++' then its MM-DD-YYYY format.
thanks
‎2009 Jan 21 4:11 PM
‎2009 Jan 21 4:13 PM
Another option is to use SPLIT
SPLIT my_date at '-' into MM DD YYYY.
or
SPLIT my_date at '-' into YYYY MM DD.
At this point you can even validate the values of MM DD and YYYY.
‎2009 Jan 21 4:24 PM
Hello Joy - the FM DATE_CHECK_PLAUSIBILTY is giving me invalid date. It don't like '-' and out put is coming as wrong.
How to read the string if it is 4 or 2 char long ?
I need to check date and month too. Say one date is mm-dd-yyyy, one is dd-mm-yyyy and another is yyyy-mm-dd. So how to decide my ultimate format or based on what? The dates are in different format and I want to read and vaidate whether first variable length is 4 or 2.
Then if it's 4, it's year.
If it's 2, need to decide whether it's greater than 12 or not. If yes, it would be date, not month.
I know what I want but need help from coding prospective. I am an BW guy, not ABAPer.
Thanks.
‎2009 Jan 21 4:26 PM
Hello Mau,
From my perspective Eric gave the simplest soln of all.
If the date is 21-01-2009 format is DD-MM-YYYY or if date is 01-21-2009 its MM-DD-YYYY.
But if the date is 01-02-2009 it can be MM-DD-YYYY or DD-MM-YYYY. This cannot be coded for !!!
Suhas
‎2009 Jan 21 4:36 PM
‎2009 Jan 21 4:21 PM
I think the simpliest way is, if you just simply check is the third character is '-' or not:
IF date+2(1) EQ '-'.
==> date has DD-MM-YYYY format
ELSE.
==> date has YYYY-MM-DD format
ENDIF.
‎2009 Jan 21 4:23 PM
Hello
IF date+2(1) EQ '-'.
==> date has DD-MM-YYYY format
ELSE.
==> date has YYYY-MM-DD format
ENDIF.
date has DD-MM-YYYY format
As per the original poster:
If it is 2, itu2019s a day or month the format would be DD-MM-YYYY or MM-DD-YYYY.
Date format can be MM-DD-YYYY as well )
BR,
Suhas
Edited by: Suhas Saha on Jan 21, 2009 9:53 PM
‎2009 Jan 21 4:32 PM
>
> As per the original poster:
>
If it is 2, itu2019s a day or month the format would be DD-MM-YYYY or MM-DD-YYYY.
>
> Date format can be MM-DD-YYYY as well )
yes, I forgot about this one...
But as you pointed out, in some cases it cannot be decided programatically, if the format is DD-MM... or MM-DD...
‎2009 Jan 21 4:35 PM
I don't think there's any totally reliable way of dong this. The simplest approach would be to require the input to be in internal format (YYYYMMDD).
Rob
‎2009 Jan 21 6:33 PM
I appreciate all of your helps. You guys are just great.
Thanks again and keep up the good work.