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 and time range validatation.

Former Member
0 Likes
1,292

Dear experts,

Let's say I have a blocking date and time period

12/05/2008 23:00 and

13/05/2008 07:00.

And now my problem is how do I program to check whether the current time is within the given time period as mentioned above?

Say, the current date and time now is 12/05/2008 23:45. Is there any standard function can validate it?

Thanks for everyone will can provide the answer.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
991

You can the current date and time from the systems variables SY-DATM and SY-UZEIT. Write a code as:


PARAMETERS: p_date1 TYPE datum obligatory,
            p_time1 TYPE syuzeit obligatory,
            p_date2 TYPE datum obligatory,
            p_time2 TYPE syuzeit obligatory.


AT SELECTION-SCREEN.
IF sy-datum NOT BETWEEN p_date1 AND p_date2.

  MESSAGE e001(ztest) WITH 'Invalid Date'.

ELSEIF sy-datum = p_date1.
  IF NOT sy-uzeit GE p_time1.
    MESSAGE e001(ztest) WITH 'Invalid Time'.
  ENDIF.
ELSEIF sy-datum = p_date2.
  IF NOT sy-uzeit lE p_time2.
    MESSAGE e001(ztest) WITH 'Invalid Time'.
  ENDIF.
ENDIF.

Hope this code helps.

2 REPLIES 2
Read only

Former Member
0 Likes
991

hi there....

the current date is stored in the system variable sy-datum and the current time resides in sy-uzeit. So u can use these two variables to check whether the current time and date is within ur defined limits. to define the limit, make sure the variables which hold the value of ur limiting date and time, should be declared as of type sy-datum and sy-uzeit.

Do reward if helpful or get back if u hav further queries.

Read only

Former Member
0 Likes
992

You can the current date and time from the systems variables SY-DATM and SY-UZEIT. Write a code as:


PARAMETERS: p_date1 TYPE datum obligatory,
            p_time1 TYPE syuzeit obligatory,
            p_date2 TYPE datum obligatory,
            p_time2 TYPE syuzeit obligatory.


AT SELECTION-SCREEN.
IF sy-datum NOT BETWEEN p_date1 AND p_date2.

  MESSAGE e001(ztest) WITH 'Invalid Date'.

ELSEIF sy-datum = p_date1.
  IF NOT sy-uzeit GE p_time1.
    MESSAGE e001(ztest) WITH 'Invalid Time'.
  ENDIF.
ELSEIF sy-datum = p_date2.
  IF NOT sy-uzeit lE p_time2.
    MESSAGE e001(ztest) WITH 'Invalid Time'.
  ENDIF.
ENDIF.

Hope this code helps.