Application Development 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: 

how to judge if one string is date or time

Former Member
0 Kudos
1,418

hi everyone,

how to get to check if one string means date or time? Any sugestion is appreciated.

Julian

1 ACCEPTED SOLUTION

Former Member
0 Kudos
409

HI,

DATA: FLD LIKE SY-DATUM,

FLD1 LIKE SY-UZEIT,

F_TYPE(4),

F_TYPE1(4).

DESCRIBE FIELD FLD TYPE F_TYPE.

DESCRIBE FIELD FLD1 TYPE F_TYPE1.

WRITE: F_TYPE,F_TYPE1..

if f_type = 'D'

write 'date'.

elseif f_type = 'T'.

write 'time'.

endif.

Regards

amole

11 REPLIES 11

Former Member
0 Kudos
409

Use the FM DATE_CHECK_PLAUSIBILITY to check if the passed parameter is a date or not. If an exception is raised it is not a date.

Former Member
0 Kudos
409

Hi Julian

can you give more details?

Have you a generic string field or do you have a field of which you don't now the type. In this case there is a class that give you runtime the type of a field.

Bye

enzo

Former Member
0 Kudos
409

You can play as well with abap operator 'CP' - contain pattern, but I suppose it is the last thing worth doing.

former_member181962
Active Contributor
0 Kudos
409

A formatted time field wil be of 8 characters(Along with separators).

A formatted date field wil be of 10 characters(Along with separators).

An unformatted time field wil be of 6 characters(Along with separators).

An unformatted date field wil be of 8 characters(Along with separators).

Find the length.

len = strlen( v_var ).

case len.

when 8.

Write:/ 'Its Time'.

when 10.

Write:/ 'Its Date'.

endcase.

Regards,

Ravi

Former Member
0 Kudos
409

Hi,

use describe

DATA: FLD(8) TYPE N,

F_TYPE.

DESCRIBE FIELD FLD TYPE F_TYPE.

Result: F_TYPE contains the value 'N'.

Regards

amole

Former Member
0 Kudos
410

HI,

DATA: FLD LIKE SY-DATUM,

FLD1 LIKE SY-UZEIT,

F_TYPE(4),

F_TYPE1(4).

DESCRIBE FIELD FLD TYPE F_TYPE.

DESCRIBE FIELD FLD1 TYPE F_TYPE1.

WRITE: F_TYPE,F_TYPE1..

if f_type = 'D'

write 'date'.

elseif f_type = 'T'.

write 'time'.

endif.

Regards

amole

0 Kudos
409

Hi erveryone,

sorry, maybe i didn't explain it too detail. I read data from a text file, so all data strings of type c initially. But i wanna check if these data are correct date or time format. How to do that?

Thanks.

Julian

0 Kudos
409

an example of CP usage:

if string CP '+++..+'.

...

elseif string CP ':'.

else...

Message was edited by: Tomasz Kozerski

0 Kudos
409

Hi Julian,

You can use the FMs:

DATE_CHECK_PLAUSIBILITY Date plausibility check

TIME_CHECK_PLAUSIBILITY Time plausibility check

for checking the string for validity of date or time.

Usage:

call function 'DATE_CHECK_PLAUSIBILITY'

exporting

date = v_date exceptions

plausibility_check_failed = 1

others = 2.

if sy-subrc <> 0.

Write:/ 'NOt a valid date'.

endif.

call function 'TIME_CHECK_PLAUSIBILITY'

exporting

time = v_time

exceptions

others = 1.

if sy-subrc ne 0.

Write:/ 'NOt a valid time'.

endif.

Regards,

Ravi

Message was edited by: Ravi Kanth Talagana

0 Kudos
409

Julian

before to use one of right solution above, do a MOVE.

MOVE $your_variable$ TO $variable_to_test$

$your_variable$ is a sequence of CHAR(8) or CHAR(10), you know.

$variable_to_test$ could be LIKE sy-datum or something else.

Former Member
0 Kudos
409

Hi julian ,

just give the example for a string how u are storing the formats for date and time in ur system ,

i mean what is the length of the date field and time field in ur text format

will it be same ,,if so give us a value (or a set of values )to work on a specific logic

cause system takes 8 chars for date field and 6 chars for time field ,,

also ur requirement is asking for a date or time check on a specific string ,

but i cant put the same string for two fields check ...

???

if that is the scenario y dont u put

field string

DXXXXXX,

TXXXXXX,

DXXXXXX,

DXXXXXX,

TXXXXXX,

this way ..

differentiate with a tag

field string+0(1) = 'D', --->DATE FIELD

ELSE TIME FIELD.

regards,

vijay

data date type d value '20061014'.

DATA TIME TYPE T VALUE '154633'.

WRITE (8) TIME USING EDIT MASK '__:__:__'. "Output: 15:46:33

write (10) date using edit mask '__/__/____'.

write time using edit mask '______'.

*my logic is system uses internally 8 chars for date field and 6 chars

*for time field