<?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: How to find out the difference between two datatime values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/558050#M155685</link>
    <description>&lt;P&gt;To find the time in the last day just use TIMEPART() on the datetime value.&lt;/P&gt;
&lt;P&gt;To find the time left in a day the take difference between now and the beginning of tomorrow.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;now=datetime();
rest_of_day = intnx('dtday',now,1,'B') - now;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps between now and end of today?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rest_of_day = intnx('dtday',now,0,'E') - now;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Play with it until you get total to be 80 minutes and not 79 minutes and 59 seconds or 80 minutes and 1 second.&lt;/P&gt;</description>
    <pubDate>Sat, 11 May 2019 16:09:13 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-05-11T16:09:13Z</dc:date>
    <item>
      <title>How to find out the difference between two datatime values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/555528#M154607</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;I want to find out the diffrerence between two date values as per that day wise..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;example;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input id startdate enddate;&lt;BR /&gt;informat startdate enddate datetime20.;&lt;BR /&gt;format startdate enddate datetime20.;&lt;BR /&gt;cards;&lt;BR /&gt;1 1May2019:11:10:00 2May2019:00:30:00&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I conider the time format as 12 hrs then the difference is 1hr 30 mins,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1 hrs&lt;/STRONG&gt; for &lt;STRONG&gt;1st of may&lt;/STRONG&gt; and &lt;STRONG&gt;30&lt;/STRONG&gt; mins for &lt;STRONG&gt;2 of may&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;like wise I want to find out the difference between two datatime values..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 04:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/555528#M154607</guid>
      <dc:creator>vThanu</dc:creator>
      <dc:date>2019-05-02T04:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out the difference between two datatime values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/555539#M154611</link>
      <description>&lt;P&gt;How do you distinguishe 11am to 11pm reading your data like this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 06:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/555539#M154611</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-02T06:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out the difference between two datatime values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/557356#M155363</link>
      <description>Consider as 24 hrs time format..&lt;BR /&gt;cards;&lt;BR /&gt;1 1May2019:23:10:00 2May2019:00:30:00&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Thu, 09 May 2019 05:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/557356#M155363</guid>
      <dc:creator>vThanu</dc:creator>
      <dc:date>2019-05-09T05:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out the difference between two datatime values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/557357#M155364</link>
      <description>&lt;P&gt;The difference between two datetime values is a number of seconds.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dur_seconds = enddatetime - startdatetime;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To find the difference in DAYS convert them to date values first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dur_days= datepart(enddatetime) - datepart(startdatetime);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or divide the seconds by the number of seconds in a day.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dur_days = int(dur_seconds/'24:00't);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 06:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/557357#M155364</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-09T06:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out the difference between two datatime values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/557359#M155366</link>
      <description>&lt;P&gt;Your question isn't clear.&amp;nbsp; Please restate your logic as to why your sample data should return 1.5 hours.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regardless, perhaps this helps...or not &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id startdate enddate;
informat startdate enddate datetime20.;
format startdate enddate datetime20.;
cards;
1 1May2019:23:10:00 2May2019:00:30:00
2 1May2019:23:10:00 5May2019:12:34:56
;
run;

data want;
   set have;
   day_diff=intck('dtday',startdate,enddate);
   hour_diff=intck('hour',startdate,enddate);   
   min_diff=intck('minute',startdate,enddate);
   sec_diff=intck('second',startdate,enddate);
   hours_frac1=min_diff/60;
   hours_frac2=sec_diff/(60*60);
   mins_frac=sec_diff/60;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See the doc for additional options for the INTCK function.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 06:20:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/557359#M155366</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-09T06:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out the difference between two datatime values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/558016#M155661</link>
      <description>Here we are getting difference between two date like 1 day or 80 mins so on…..&lt;BR /&gt;but what I am exactly looking is in that 80 mins (1May2019:23:10:00 - 2May2019:00:30:00)&lt;BR /&gt;50 mins in 1st of May and 30 mins for 2nd of May.&lt;BR /&gt;&lt;BR /&gt;I am looking for the split, if the date/day changes then it should show into separately 50mins &amp;amp; 30 mins.&lt;BR /&gt;&lt;BR /&gt;Hope you got my point.&lt;BR /&gt;Thanks in advance</description>
      <pubDate>Sat, 11 May 2019 08:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/558016#M155661</guid>
      <dc:creator>vThanu</dc:creator>
      <dc:date>2019-05-11T08:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out the difference between two datatime values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/558050#M155685</link>
      <description>&lt;P&gt;To find the time in the last day just use TIMEPART() on the datetime value.&lt;/P&gt;
&lt;P&gt;To find the time left in a day the take difference between now and the beginning of tomorrow.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;now=datetime();
rest_of_day = intnx('dtday',now,1,'B') - now;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps between now and end of today?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rest_of_day = intnx('dtday',now,0,'E') - now;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Play with it until you get total to be 80 minutes and not 79 minutes and 59 seconds or 80 minutes and 1 second.&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 16:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-the-difference-between-two-datatime-values/m-p/558050#M155685</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-11T16:09:13Z</dc:date>
    </item>
  </channel>
</rss>

