Skip to Content
author's profile photo Former Member
Former Member

how to judge if one string is date or time

hi everyone,

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

Julian

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 09:14 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 09:02 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 09:09 AM

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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 24, 2006 at 09:10 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 09:11 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 09:06 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 11:46 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.