<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Date/time-operations - need help in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-time-operations-need-help/m-p/5334605#M1229113</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your answers. Now I've created a small dummy-report, that tests the logic. And I think it seems to be okay.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also check it if you want to with this small report:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

REPORT  zjz_test_timediff.

PARAMETERS: p_dat1  TYPE sydatum DEFAULT sy-datum,
            p_zei1  TYPE syuzeit DEFAULT sy-uzeit,
            p_dat2  TYPE sydatum DEFAULT sy-datum,
            p_zei2  TYPE syuzeit DEFAULT sy-uzeit.

SELECTION-SCREEN: SKIP 2.

PARAMETERS: p_diff type p.

SELECTION-SCREEN: SKIP 2.

PARAMETERS: p_dat3  TYPE sydatum,
            p_zei3  TYPE syuzeit.


DATA: lv_timestamp_orig   TYPE timestamp,
      lv_timestamp_new    TYPE timestamp,
      lv_diff             TYPE p.

AT SELECTION-SCREEN.

  PERFORM idoc_compare_dates USING p_dat1
                                   p_zei1
                                   p_dat2
                                   p_zei2
                          CHANGING p_diff.

  PERFORM idoc_calc_single_date USING p_diff
                                      p_dat1
                                      p_zei1
                             CHANGING p_dat3
                                      p_zei3.


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  IDOC_COMPARE_DATES
*&amp;amp;---------------------------------------------------------------------*
FORM idoc_compare_dates  USING    iv_date_orig
                                  iv_time_orig
                                  iv_date_new
                                  iv_time_new
                         CHANGING cv_diff       TYPE p.

  DATA: lv_timestamp_orig    TYPE timestamp,
        lv_timestamp_new     TYPE timestamp.


  CONVERT DATE iv_date_orig TIME iv_time_orig
    INTO TIME STAMP lv_timestamp_orig TIME ZONE sy-zonlo.
  CONVERT DATE iv_date_new TIME iv_time_new
    INTO TIME STAMP lv_timestamp_new TIME ZONE sy-zonlo.

  cv_diff = lv_timestamp_new - lv_timestamp_orig.

ENDFORM.                    " IDOC_COMPARE_DATES

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  IDOC_CALC_SINGLE_DATE
*&amp;amp;---------------------------------------------------------------------*
FORM idoc_calc_single_date  USING    iv_diff      TYPE p
                                     iv_date_orig
                                     iv_time_orig
                            CHANGING cv_date_new
                                     cv_time_new.

  DATA: lv_timestamp_orig   TYPE timestamp,
        lv_timestamp_new    TYPE timestamp.

  CONVERT DATE iv_date_orig TIME iv_time_orig
    INTO TIME STAMP lv_timestamp_orig TIME ZONE sy-zonlo.

  lv_timestamp_new = lv_timestamp_orig + iv_diff.

  CONVERT TIME STAMP lv_timestamp_new TIME ZONE sy-zonlo
    INTO DATE cv_date_new TIME cv_time_new.

ENDFORM.                    " IDOC_CALC_SINGLE_DATE

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 14 Mar 2009 13:31:13 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-03-14T13:31:13Z</dc:date>
    <item>
      <title>Date/time-operations - need help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-time-operations-need-help/m-p/5334602#M1229110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a simple question but i don't have really good ideas to solve the problem with ABAP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the situation in which I need help:&lt;/P&gt;&lt;P&gt;I have many date/time-pairs (every in a single variable of type d and t). Now I want to compare one date/time-pair with a given date (also as pair). This will give a time difference between the two dates.&lt;/P&gt;&lt;P&gt;After that I want that all other date/time-pairs are shifted by this time difference (can be + and -).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So now my solution yet:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
* FORM for calculation the time difference between 2 dates
FORM idoc_compare_dates  USING    iv_date_orig
                                  iv_time_orig
                                  iv_date_new
                                  iv_time_new
                         CHANGING cv_diff       TYPE p.

  DATA: lv_timestamp_orig    TYPE timestamp,
        lv_timestamp_new     TYPE timestamp.

* Creating timestamps for comparison
  CONVERT DATE iv_date_orig TIME iv_time_orig
    INTO TIME STAMP lv_timestamp_orig TIME ZONE sy-zonlo.
  CONVERT DATE iv_date_new TIME iv_time_new
    INTO TIME STAMP lv_timestamp_new TIME ZONE sy-zonlo.

* Calculation the time difference 
  cv_diff = lv_timestamp_new - lv_timestamp_orig.

ENDFORM.                    " IDOC_COMPARE_DATES

* *********************************************************************

* FORM for shifting a date by the time period calculated in the first FORM
FORM idoc_calc_single_date  USING    iv_diff      TYPE p
                                     iv_date_orig
                                     iv_time_orig
                            CHANGING cv_date_new
                                     cv_time_new.

  DATA: lv_timestamp_orig   TYPE timestamp,
        lv_timestamp_new    TYPE timestamp.

* Creating a timestamp for the original date
  CONVERT DATE iv_date_orig TIME iv_time_orig
    INTO TIME STAMP lv_timestamp_orig TIME ZONE sy-zonlo.

* Shifting the date
  lv_timestamp_new = lv_timestamp_orig + iv_diff.

* Creating the new date into the output-variables
  CONVERT TIME STAMP lv_timestamp_new TIME ZONE sy-zonlo
    INTO DATE cv_date_new TIME cv_time_new.

ENDFORM.                    " IDOC_CALC_SINGLE_DATE


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure if this coding above is really correct. Can you please check it? Perhaps you have also other ideas to solve this problem?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Mar 2009 13:18:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/date-time-operations-need-help/m-p/5334602#M1229110</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-14T13:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Date/time-operations - need help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-time-operations-need-help/m-p/5334603#M1229111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;u can check this class&lt;/P&gt;&lt;P&gt;CL_ABAP_TSTMP&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it has methods to compare timestamps, add, subtract etc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="16" __jive_macro_name="size"&gt;кu03B1ятu03B9к&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Mar 2009 13:25:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/date-time-operations-need-help/m-p/5334603#M1229111</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-14T13:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Date/time-operations - need help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-time-operations-need-help/m-p/5334604#M1229112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As far as I think its absolutely correct....&lt;/P&gt;&lt;P&gt;but also try with one small change if you get the required output...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;* Shifting the date
  lv_timestamp_new = lv_timestamp_orig + iv_diff.   "  if iv_diff is negative it will be subtract automatically.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Siddarth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Mar 2009 13:28:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/date-time-operations-need-help/m-p/5334604#M1229112</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-14T13:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Date/time-operations - need help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-time-operations-need-help/m-p/5334605#M1229113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your answers. Now I've created a small dummy-report, that tests the logic. And I think it seems to be okay.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also check it if you want to with this small report:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

REPORT  zjz_test_timediff.

PARAMETERS: p_dat1  TYPE sydatum DEFAULT sy-datum,
            p_zei1  TYPE syuzeit DEFAULT sy-uzeit,
            p_dat2  TYPE sydatum DEFAULT sy-datum,
            p_zei2  TYPE syuzeit DEFAULT sy-uzeit.

SELECTION-SCREEN: SKIP 2.

PARAMETERS: p_diff type p.

SELECTION-SCREEN: SKIP 2.

PARAMETERS: p_dat3  TYPE sydatum,
            p_zei3  TYPE syuzeit.


DATA: lv_timestamp_orig   TYPE timestamp,
      lv_timestamp_new    TYPE timestamp,
      lv_diff             TYPE p.

AT SELECTION-SCREEN.

  PERFORM idoc_compare_dates USING p_dat1
                                   p_zei1
                                   p_dat2
                                   p_zei2
                          CHANGING p_diff.

  PERFORM idoc_calc_single_date USING p_diff
                                      p_dat1
                                      p_zei1
                             CHANGING p_dat3
                                      p_zei3.


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  IDOC_COMPARE_DATES
*&amp;amp;---------------------------------------------------------------------*
FORM idoc_compare_dates  USING    iv_date_orig
                                  iv_time_orig
                                  iv_date_new
                                  iv_time_new
                         CHANGING cv_diff       TYPE p.

  DATA: lv_timestamp_orig    TYPE timestamp,
        lv_timestamp_new     TYPE timestamp.


  CONVERT DATE iv_date_orig TIME iv_time_orig
    INTO TIME STAMP lv_timestamp_orig TIME ZONE sy-zonlo.
  CONVERT DATE iv_date_new TIME iv_time_new
    INTO TIME STAMP lv_timestamp_new TIME ZONE sy-zonlo.

  cv_diff = lv_timestamp_new - lv_timestamp_orig.

ENDFORM.                    " IDOC_COMPARE_DATES

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  IDOC_CALC_SINGLE_DATE
*&amp;amp;---------------------------------------------------------------------*
FORM idoc_calc_single_date  USING    iv_diff      TYPE p
                                     iv_date_orig
                                     iv_time_orig
                            CHANGING cv_date_new
                                     cv_time_new.

  DATA: lv_timestamp_orig   TYPE timestamp,
        lv_timestamp_new    TYPE timestamp.

  CONVERT DATE iv_date_orig TIME iv_time_orig
    INTO TIME STAMP lv_timestamp_orig TIME ZONE sy-zonlo.

  lv_timestamp_new = lv_timestamp_orig + iv_diff.

  CONVERT TIME STAMP lv_timestamp_new TIME ZONE sy-zonlo
    INTO DATE cv_date_new TIME cv_time_new.

ENDFORM.                    " IDOC_CALC_SINGLE_DATE

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Mar 2009 13:31:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/date-time-operations-need-help/m-p/5334605#M1229113</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-14T13:31:13Z</dc:date>
    </item>
  </channel>
</rss>

