<?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>Question Re: Time Difference calculation in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/time-difference-calculation/qaa-p/12410408#M4645490</link>
    <description>&lt;P&gt;This would be easier if you had DateTime values, as you could use DateDiff to get the difference.  However, assuming that 1 - you're converting both begin time and end time to times in similar formula and 2 - you want the difference between the two in minutes, you would do something like this to get the number of minutes between the two times (it only works if the two times are in the same day):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;//Start by adding leading 0's so we don't need to look at the length...
StringVar sStartTime := Right("0" + ToText({OCLG.BeginTime}, 0, ""), 4);
StringVar sEndTime := Right("0" + ToText({OCLG.EndTime}, 0, ""), 4);
NumberVar iStartMinutes := 0;
NumberVar iEndMinutes := 0;
//Convert the strings to minutes
iStartMinutes := ToNumber(Left(sStartTime, 2)) * 60 + ToNumber(Right(sStartTime, 2);
iEndMinutes := ToNumber(Left(sEndTime, 2)) * 60 + ToNumber(Right(sEndTime, 2);
//Get the difference in minutes
iEndMinutes - iStartMinutes
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If you need the result as a time you could do something like this with the result of the above formula (which I'll call {@MinuteDiff}&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CTime(ToText({@MinuteDiff} \ 60, 0, "") + ":" + ToText({@MinuteDiff} mod 60, 0, ""))&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note that the first part of this equation uses a backslash for "integer divide" instead of the normal forward slash that is used for division.  This gives you the integer part of the division without rounding.  The "mod" in the second part gives you the remainder of the integer divide as a whole number.&lt;/P&gt;&lt;P&gt;-Dell&lt;/P&gt;</description>
    <pubDate>Thu, 08 Apr 2021 18:07:35 GMT</pubDate>
    <dc:creator>DellSC</dc:creator>
    <dc:date>2021-04-08T18:07:35Z</dc:date>
    <item>
      <title>Time Difference calculation</title>
      <link>https://community.sap.com/t5/technology-q-a/time-difference-calculation/qaq-p/12410406</link>
      <description>&lt;P&gt;Hi everyone ı got a problem about calculating difference between two time fields.When ı am trying Starttime-Endtime it doesn't show result by time because my time fields are integer and ı couldn't find a way to change it... I can change my time fields to AM and PM but in this case ı can't handle the Starttime-Endtime.&lt;/P&gt;
  &lt;P&gt;The formula I am using to display time in AM and PM :&lt;/P&gt;
  &lt;P&gt;StringVar sMyTime := ToText({OCLG.BeginTime}, 0, "");&lt;/P&gt;
  &lt;P&gt; IF Len(sMyTime) = 3&lt;/P&gt;
  &lt;P&gt; Then cTime(sMyTime[1] &amp;amp; ":" &amp;amp; sMyTime[2 to 3] &amp;amp; " " &amp;amp; "AM")&lt;/P&gt;
  &lt;P&gt; else IF Len(sMyTime) = 4&lt;/P&gt;
  &lt;P&gt; Then cTime(sMyTime[1 to 2] &amp;amp; ":" &amp;amp; sMyTime[3 to 4] &amp;amp; " " &amp;amp; "AM")&lt;/P&gt;
  &lt;P&gt;I NEED HELP IN ASAP!!!&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 14:55:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/time-difference-calculation/qaq-p/12410406</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-04-08T14:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: Time Difference calculation</title>
      <link>https://community.sap.com/t5/technology-q-a/time-difference-calculation/qaa-p/12410407#M4645489</link>
      <description>&lt;P&gt;Thank you for
visiting SAP Community to get answers to your questions. Since this is your
first question, I recommend that you familiarize yourself with our Q&amp;amp;A
Tutorial: &lt;A href="https://developers.sap.com/tutorials/community-qa.html"&gt;https://developers.sap.com/tutorials/community-qa.html&lt;/A&gt;,
as it provides tips for preparing questions that draw responses from our
members. Should you wish, you can revise your question by selecting Actions,
then Edit.&lt;/P&gt;&lt;P&gt;By adding a picture
to your profile you encourage readers to respond: &lt;A href="https://www.youtube.com/watch?v=46bt1juWUUM"&gt;https://www.youtube.com/watch?v=46bt1juWUUM&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Many thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 14:56:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/time-difference-calculation/qaa-p/12410407#M4645489</guid>
      <dc:creator>former_member34</dc:creator>
      <dc:date>2021-04-08T14:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Time Difference calculation</title>
      <link>https://community.sap.com/t5/technology-q-a/time-difference-calculation/qaa-p/12410408#M4645490</link>
      <description>&lt;P&gt;This would be easier if you had DateTime values, as you could use DateDiff to get the difference.  However, assuming that 1 - you're converting both begin time and end time to times in similar formula and 2 - you want the difference between the two in minutes, you would do something like this to get the number of minutes between the two times (it only works if the two times are in the same day):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;//Start by adding leading 0's so we don't need to look at the length...
StringVar sStartTime := Right("0" + ToText({OCLG.BeginTime}, 0, ""), 4);
StringVar sEndTime := Right("0" + ToText({OCLG.EndTime}, 0, ""), 4);
NumberVar iStartMinutes := 0;
NumberVar iEndMinutes := 0;
//Convert the strings to minutes
iStartMinutes := ToNumber(Left(sStartTime, 2)) * 60 + ToNumber(Right(sStartTime, 2);
iEndMinutes := ToNumber(Left(sEndTime, 2)) * 60 + ToNumber(Right(sEndTime, 2);
//Get the difference in minutes
iEndMinutes - iStartMinutes
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If you need the result as a time you could do something like this with the result of the above formula (which I'll call {@MinuteDiff}&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CTime(ToText({@MinuteDiff} \ 60, 0, "") + ":" + ToText({@MinuteDiff} mod 60, 0, ""))&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note that the first part of this equation uses a backslash for "integer divide" instead of the normal forward slash that is used for division.  This gives you the integer part of the division without rounding.  The "mod" in the second part gives you the remainder of the integer divide as a whole number.&lt;/P&gt;&lt;P&gt;-Dell&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 18:07:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/time-difference-calculation/qaa-p/12410408#M4645490</guid>
      <dc:creator>DellSC</dc:creator>
      <dc:date>2021-04-08T18:07:35Z</dc:date>
    </item>
  </channel>
</rss>

