cancel
Showing results for 
Search instead for 
Did you mean: 

comparing dates

12-21-2012 8:36 AM
ravi_kumar221 Participant
3764 views 14 comments
0 Likes
SAP Managed Tags
Subscribe

masters in my application i have to compare 2 dates in  2 variable 

var1 var2 i have to check whether var1 is greater then  var2 or not how to do it please tell me

Moderator message: very basic, please search for information before posting.

Message was edited by: Thomas Zloch

0 Likes

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Likes

Use FM HR_HK_DIFF_BT_2_DATES to  get difference between two dates .

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes

You can simply use the relational operators > or < on your dates if they are in the internal date format (YYYYMMDD).

Former Member
0 Likes

hi ravi

you can compare dates by simply using the keyword GT .

Ex:

If d1 gt d2 .

write d1.

else .

write d2.

endif.

regards

vaibhav

Former Member
0 Likes

Hi,

You can simply do it as follow:

if date1 gt date2.

write:'date1 is greater then date2 '.

else.

write:'date2 is greater then date1 '.

endif.

Your code is not working because:

l_diff must be of type sy-datum ,Since date1 and date2 are of type sy-datum,else proper conversion will not haapen.In your code i_diff is of type 'i'.

ujjaval-bhalala
Explorer
0 Likes

Hi ravi kumar,

First declare two variable with data type D,

Then you can easily compare these variable with arithmetic operators.

ravi_kumar221
Participant
0 Likes

if  wa_header-POSTING_DATE > wa_headerctr-vper_end .
          wa_message-msgid = 'ZSRM_BBP_DOC_CHECK' .
               wa_message-msgno  =  '007'.
               wa_message-msgty = 'E'.
               APPEND wa_message TO et_messages.
         endif.

my code


Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes

Please check the below link which will give function modules available for calculating date related operations.

http://scn.sap.com/thread/3283689

hope this helps

Former Member
0 Likes

Hi Ravi,

Can you please check the date format of both the work areas.

Try this in debugging mode and if they are different make them same.

Regards,

Amit

Former Member
0 Likes

Hi,

You can compare like

if var1 < var2

----Do Some thing-----

endif.

Hope this will help.

Regards,

Amit

Former Member
0 Likes

Hi see the following logic.

data: l_diff type i.

<d1>-date1

<d2>-date2

l_diff = <d1> - <d2>.

if l_diff lt 0.

<d1> is less than <d2>

else.

<d1> is greater than <d2>

endif.

Former Member
0 Likes

You can compare dates using simple mathematical operators.

ravi_kumar221
Participant
0 Likes

im doing thatbut it is not working

Former Member
0 Likes

can you paste the code?? it will be helpful to explain

Former Member
0 Likes

May be the dates are in different format than the MMDDYYYY format. so you can either mask them to this format or use the following module ...

call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

exporting

i_date_from = FROMDATE

i_date_to = TODATE

* I_FLG_SEPARATE = ' '

IMPORTING

E_DAYS = EDAYS

E_MONTHS = EMONTHS.

* E_YEARS = EYEARS.