Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Date format validation

Former Member
0 Likes
4,801

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.

1 ACCEPTED SOLUTION
Read only

JozsefSzikszai
Active Contributor
0 Likes
4,329

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.

11 REPLIES 11
Read only

Former Member
0 Likes
4,329

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

Read only

former_member156446
Active Contributor
0 Likes
4,329

search the forum first...

Read only

Former Member
0 Likes
4,329

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.

Read only

0 Likes
4,329

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.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
4,329

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

Read only

0 Likes
4,329

This message was moderated.

Read only

JozsefSzikszai
Active Contributor
0 Likes
4,330

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.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
4,329

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

Read only

0 Likes
4,329

>

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

Read only

Former Member
0 Likes
4,329

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

Read only

0 Likes
4,329

I appreciate all of your helps. You guys are just great.

Thanks again and keep up the good work.