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

Get date format value

Former Member
0 Likes
3,179

Hi ,

I have a field for date in a incoming file. The file can have date in any of the following format DD.MM.YYYY, MM/DD/YYYY, MM-DD-YYYY, YYYY.MM.DD, YYYY/MM/DD or YYYY-MM-DD. How can I decide which exact date format is entered in file? is there any FM or any other way to decide the Date format?

10 REPLIES 10
Read only

Former Member
0 Likes
2,106

Basic date questions are not allowed. Please search in SCN you will find many posts related to this.

Read only

Former Member
0 Likes
2,106

HI,

i have already searched SCN but most of the threads are related to conversion of Date format. My question is to identify the user entered date format with the help of FM or any other easy way. otherwise simply i can write a piece of code to decide the date format based on the separator value.

Thanks.

Read only

matt
Active Contributor
0 Likes
2,106

Date questions are asked so frequently, that they will often be rejected. In this case I think the interest is just about sufficient for the thread to remain.

matt

Read only

Former Member
0 Likes
2,106

Hi,

I think there is no such FM you have to write your own logic to handel it,

best way will be to fix the formates for input or at least accept only predefined formates not in any formate.

Regards

Bikas

Read only

Former Member
0 Likes
2,106

Even with the field separator, you cannot make out the format of date.

MM.DD.YYYY and DD.MM.YYYY can have the same values.

A solution to this this could be adding another field with dropdown on selection screen as 'date format'. User, along with date will also provide the date format. with help of this format, you can process the dates in your code.

Hope it helps,

Sumit

Read only

Former Member
0 Likes
2,106

Hi Sumit,

Thanks for your reply. I will be using only following specific DD.MM.YYYY, MM/DD/YYYY, MM-DD-YYYY, YYYY.MM.DD, YYYY/MM/DD or YYYY-MM-DD. So i think, there will not be any conflict while deciding the date format based on separator.

Thanks.

Read only

0 Likes
2,106

Hi,

Probably we can use something as we have done in the below code. Take the idea from here and build the logic.

data: date type char10,

date1 type char10,

sign type char15.

date = '120110'.

date1 = sy-datum+0(2).

CONCATENATE '__/__/' date1 '__' into sign.

WRITE date USING EDIT MASK sign TO date1.

write date1.

Read only

Former Member
0 Likes
2,106

Hi ,

You need to understand one thing that before you do any processing of the data from the legacy file there should be a common

understanding between you and the client on the field you are goind to use .

Suppose there is a field as 02/02/2010 in ur file . Neither the client nor you can say if its mm/d/yyyy format or dd/mm/yyyy format .

So please discuss this with client and get the field in what format they are looking at and appropiately build the code for it .

Br,

Vijay.

Read only

Former Member
0 Likes
2,106

Hi Nikhil,

if you are very sure that the formats are going to be these only, then you can go ahead with string manipulations.

use CP, CN, CO ..

or use

split text1 at '/' into table it_text. " chops the string at '/' and puts sequentially in table it_text(field shud b char)

Use of "case" has to be done in your requirement again.

Regards,

Sumit

Read only

Former Member
0 Likes
2,106

hey,

try to look in the class CL_ABAP_DATFM

i think it may help you.