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

Comparing dates

Hi ,

In My program i need to compare date and time value

with current date and time , If DATE & TIME is in the

future, I need to set the DATE & TIME to NOW.

Please help me if you know any FM or sample code

To compare the dates and time.

Thanks in advance,

RK.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 17, 2007 at 12:52 PM

    Hi,

    You can use the below :

    data : date like sy-datum value '20071231'.
    data : time like sy-uzeit value '121212'.
    at selection-screen.
    
    if date GT sy-datum.
    date = sy-datum.
    endif.
    
    if time GT sy-uzeit.
    time = sy-uzeit.
    endif.
    

    .

    Thanks,

    Sriram Ponna.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 17, 2007 at 12:52 PM

    Hi,

    You can do like this

    Loop at itab into wa.

    if wa-date NE sy-datum and wa-time NE sy-uzeit.

    wa-date = sy-datum.

    wa-time = sy-uzeit.

    modify itab from wa transporting date time.

    clear wa.

    endif.

    endloop.

    Regards,

    Satish

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 17, 2007 at 12:57 PM

    DATE_COMPUTE_DAY

    DATE_GET_WEEK

    hi put in a condition saying

    if sy-datum > ur date

    ur date = sy-datum.

    endif.

    if sy-uzeit > ur time

    ur time = sy-uzeit.

    endif.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 17, 2007 at 01:00 PM

    hi,

    a) Check this FM 'HR_HK_DIFF_BT_2_DATES'.

    b) think this two function modules can help u out..just let me know were this useful..

    SD_DATETIME_DIFFERENCE

    Give the difference in Days and Time for 2 dates

    FIMA_DAYS_AND_MONTHS_AND_YEARS

    Get number of days. Year, Months between two dates.

    by using either of one u can get the difference, if difference is -ve , set date and time to system date and time

    regards,

    pavan

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 17, 2007 at 01:06 PM

    Hi Ravi,

    Try any one of this function modules in these you compare sy-datum and sy-uzeit..

    HRVE_GET_TIME_BETWEEN_DATES

    CX_SCHED_VIA_OPERATING_TIME

    SD_DATETIME_DIFFERENCE

    SD_CALC_DURATION_FROM_DATETIME

    Plz Reward if useful.

    Mahi.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 17, 2007 at 01:21 PM

    Hi

    Ravi

    as they said you can use FM

    or if u want logic dont compare date and time explicitly

    do like this

    data:

    w_d1 int i,

    w_t1 type i,

    w_d2 type i,

    w_t2 type i,

    w_d1 = sy-datum.

    w_t1 = sy-uzeit.

    w_d2 = ur_date.

    w_t2 = ur_time.

    if (w_d1 + w_t1 ) le ( w_d2 + w_t2 ) .

    ur_date = sy-datum.

    ur_time = sy-uzeit.

    endif.

    plzzz reward if useful dont forget to reward plzz

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 17, 2007 at 01:21 PM

    Hi

    Ravi

    as they said you can use FM

    or if u want logic dont compare date and time explicitly

    do like this

    data:

    w_d1 int i,

    w_t1 type i,

    w_d2 type i,

    w_t2 type i,

    w_d1 = sy-datum.

    w_t1 = sy-uzeit.

    w_d2 = ur_date.

    w_t2 = ur_time.

    if (w_d1 + w_t1 ) le ( w_d2 + w_t2 ) .

    ur_date = sy-datum.

    ur_time = sy-uzeit.

    endif.

    plzzz reward if useful dont forget to reward plzz

    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.