<?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 calculate difference in minutes and in seconds between 2 datetime fields in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896871#M354398</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to calculate difference in minutes between two datetime fields.&lt;/P&gt;
&lt;P&gt;I want to calculate difference in seconds between two datetime fields.&lt;/P&gt;
&lt;P&gt;my calculation provide wrong results:&lt;/P&gt;
&lt;P&gt;INTCK('minute',application_DateTime,Loan_datetime)&lt;/P&gt;
&lt;P&gt;INTCK('seconds',application_DateTime,Loan_datetime)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
format  Loan_DateTime Application_DateTime  datetime20.;
input Loan_DateTime ::datetime18.  Application_DateTime ::datetime18.;
cards;
01SEP2023:09:59:00 01SEP2023:09:58:16
;
Run;

data want;
set have;
dif_minutes=INTCK('minutes',Application_DateTime,Loan_DateTime);
dif_seconds=INTCK('seconds',Application_DateTime,Loan_DateTime);
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Oct 2023 09:21:22 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2023-10-03T09:21:22Z</dc:date>
    <item>
      <title>calculate difference in minutes and in seconds between 2 datetime fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896871#M354398</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to calculate difference in minutes between two datetime fields.&lt;/P&gt;
&lt;P&gt;I want to calculate difference in seconds between two datetime fields.&lt;/P&gt;
&lt;P&gt;my calculation provide wrong results:&lt;/P&gt;
&lt;P&gt;INTCK('minute',application_DateTime,Loan_datetime)&lt;/P&gt;
&lt;P&gt;INTCK('seconds',application_DateTime,Loan_datetime)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
format  Loan_DateTime Application_DateTime  datetime20.;
input Loan_DateTime ::datetime18.  Application_DateTime ::datetime18.;
cards;
01SEP2023:09:59:00 01SEP2023:09:58:16
;
Run;

data want;
set have;
dif_minutes=INTCK('minutes',Application_DateTime,Loan_DateTime);
dif_seconds=INTCK('seconds',Application_DateTime,Loan_DateTime);
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 09:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896871#M354398</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-10-03T09:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference in minutes and in seconds between 2 datetime fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896873#M354399</link>
      <description>&lt;P&gt;Not following you, they are the same value, so difference should be 0...?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 08:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896873#M354399</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-10-03T08:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference in minutes and in seconds between 2 datetime fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896880#M354404</link>
      <description>&lt;P&gt;sorry I wrote wrong date time values.&lt;/P&gt;
&lt;P&gt;Anyway,I saw the correct way to do it:&lt;/P&gt;
&lt;P&gt;for dif in&amp;nbsp; seconds need to substract the two datetimes&lt;/P&gt;
&lt;P&gt;for dif&amp;nbsp; in minutes need to use INTCK&lt;/P&gt;
&lt;P&gt;For&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 09:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896880#M354404</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-10-03T09:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference in minutes and in seconds between 2 datetime fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896881#M354405</link>
      <description>&lt;P&gt;Your datetime fields are already measured in seconds.&amp;nbsp; So&amp;nbsp; you could use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;duration = Application_DateTime - Loan_DateTime;
dif_in_minutes = int(duration / 60);
dif_in_seconds = duration - 60*dif_in_minutes;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Oct 2023 09:24:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896881#M354405</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-10-03T09:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference in minutes and in seconds between 2 datetime fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896885#M354408</link>
      <description>&lt;P&gt;I saw that difference in seconds is calculated by:&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;Application_DateTime - Loan_DateTime;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why did you call it duration and what is the difference between duration and dif_in_seconds?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 09:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896885#M354408</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-10-03T09:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference in minutes and in seconds between 2 datetime fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896945#M354444</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's say you have a difference of 90 seconds between the two timestamps.&amp;nbsp; There are a variety of ways to express that, including (but not limited to):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;90 seconds&lt;/P&gt;
&lt;P&gt;1 minute 30 seconds&lt;/P&gt;
&lt;P&gt;1.5 minutes&lt;/P&gt;
&lt;P&gt;01:30&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So variable names are up to the programmer.&amp;nbsp; What you want is up to you.&amp;nbsp; When I looked at the problem, I thought the second expression was what you were asking for.&amp;nbsp; So I chose DURATION as the top version (90 seconds) and used it in the calculations to obtain the numbers in the second line (1 minute, 30 seconds).&amp;nbsp; But if that is not your preference, you can fiddle with it pretty easily.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 14:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/896945#M354444</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-10-03T14:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference in minutes and in seconds between 2 datetime fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/897149#M354524</link>
      <description>&lt;P&gt;Question1-&lt;/P&gt;
&lt;P&gt;What is the way to calculate the complete number of minutes difference between two datetimes via INTCK?&lt;/P&gt;
&lt;P&gt;In this example should get "1"&amp;nbsp; but with my INTCK I got "2"?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format  Loan_DateTime Application_DateTime  datetime20.;
input  Application_DateTime ::datetime18. Loan_DateTime ::datetime18.;
cards;
01SEP2023:09:57:16 01SEP2023:09:59:00
;
Run;
/**Note-datetime fields are already measured in seconds**/

Data want;
set Have;
duration_in_seconds=Loan_DateTime-Application_DateTime ;/***104 seconds**/
/*altenative way :duration_in_seconds=intck('seconds',Application_DateTime,Loan_DateTime);*/
dif_in_minutes = int(duration_in_seconds / 60);  /**1 minute**/
dif_in_seconds = duration_in_seconds - 60*dif_in_minutes;/**44 seconds***/
/*Dont USE this calc-intck('minutes',Application_DateTime,Loan_DateTime);*/
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Question2-&lt;/P&gt;
&lt;P&gt;Let's say that I want to show difference in minutes but also partial minutes.&lt;/P&gt;
&lt;P&gt;So difference between&amp;nbsp;01SEP2023:09:57:16&amp;nbsp; and&amp;nbsp;01SEP2023:09:59:00 should get 1.73&amp;nbsp; (since 44 seconds divide by 60).&lt;/P&gt;
&lt;P&gt;What is the way to calculate it please?&lt;/P&gt;
&lt;P&gt;Here I found the solution&lt;/P&gt;
&lt;P&gt;duration_in_seconds=Loan_DateTime-Application_DateTime ;/***104 seconds**/&lt;BR /&gt;duration_in_minutes=duration_in_seconds/60;/***1.73***/&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 13:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/897149#M354524</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-10-04T13:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference in minutes and in seconds between 2 datetime fields</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/897320#M354573</link>
      <description>INTCK is counting the number of times a boundary is crossed.   Your program crosses a "minute" boundary twice:  once at 9:57:00, and once at 9:58:00, so you get 2.</description>
      <pubDate>Thu, 05 Oct 2023 08:07:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-difference-in-minutes-and-in-seconds-between-2/m-p/897320#M354573</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-10-05T08:07:27Z</dc:date>
    </item>
  </channel>
</rss>

