<?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 calculate time difference between two string datetime in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/833178#M329354</link>
    <description>&lt;P&gt;This isn't a very good answer ... but B8601DT seems happy when the value is just a date and no time component, while E8601DT seems to only work when there is a time component. However, I don't see where the documentation says that.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Sep 2022 16:14:50 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-09-13T16:14:50Z</dc:date>
    <item>
      <title>How to calculate time difference between two string datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/832758#M329180</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have two columns like below,&amp;nbsp; STDTC and ENDTC in string format ($100). I want to calculate the time difference between them. I tried to convert stdtc to datetime format but failed bacause only one row with time and other rows are date. Seems it cannot make this column to be both date and datetime. How to calculte ?&lt;/P&gt;&lt;P&gt;STDTC&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ENDTC&lt;/P&gt;&lt;P&gt;2022-01-03&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2022-01-03&lt;/P&gt;&lt;P&gt;2022-03-22&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2022-05-02&lt;/P&gt;&lt;P&gt;2022-06-02T10:30&amp;nbsp; &amp;nbsp; &amp;nbsp;2022-06-04&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 15:12:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/832758#M329180</guid>
      <dc:creator>Sally_Caffrey</dc:creator>
      <dc:date>2022-09-11T15:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time difference between two string datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/832760#M329182</link>
      <description>&lt;P&gt;You have to create new numeric variables from the character variables in order to work with these.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You show five dates, and one date/time ... exactly what result do you want here anyway?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input STDTC $16. ENDTC :$16.;
cards;
2022-01-03                2022-01-03
2022-03-22                2022-05-02
2022-06-02T10:30          2022-06-04 
;
data want;
     set have;
     stdtn=input(stdtc,B8601DT.);
     endtn=input(endtc,B8601DT.);
     delta=endtn-stdtn;
     format delta time16.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 16:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/832760#M329182</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-11T16:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time difference between two string datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/833175#M329351</link>
      <description>That's exactly I want. Thanks! BTW, when I try to create numeric variables from stdtc by using input(stdtc, E8601DT.), the log reports "Invalid argument to function INPUT".&lt;BR /&gt;&lt;BR /&gt;The SAS help shows that B8601DT. writes datetime values in the ISO 8601 basic notation yyyymmddThhmmssffffff. , while E8601DT. in extended notation yyyy-mm-ddThh:mm:ss.ffffff.&lt;BR /&gt;&lt;BR /&gt;Why E8601DT. reports the note ?</description>
      <pubDate>Tue, 13 Sep 2022 15:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/833175#M329351</guid>
      <dc:creator>Sally_Caffrey</dc:creator>
      <dc:date>2022-09-13T15:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time difference between two string datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/833178#M329354</link>
      <description>&lt;P&gt;This isn't a very good answer ... but B8601DT seems happy when the value is just a date and no time component, while E8601DT seems to only work when there is a time component. However, I don't see where the documentation says that.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 16:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/833178#M329354</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-13T16:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time difference between two string datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/833271#M329393</link>
      <description>Thanks a lot!</description>
      <pubDate>Wed, 14 Sep 2022 01:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/833271#M329393</guid>
      <dc:creator>Sally_Caffrey</dc:creator>
      <dc:date>2022-09-14T01:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time difference between two string datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/833370#M329429</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This isn't a very good answer ... but B8601DT seems happy when the value is just a date and no time component, while E8601DT seems to only work when there is a time component. However, I don't see where the documentation says that.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The difference in the documentation is that B8601dt includes:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-details"&gt;
&lt;DIV id="n1wnkrflw87821n12u7rhw9xzj90" class="xis-topicContent"&gt;
&lt;DIV id="p019zmyymbos42n1v7dw9dasxsr0" class="xis-paragraph"&gt;If the hour, minute, or second values are omitted, SAS uses a value of 0 for the hour, minute, or second.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;but E8601dt does not have a similar piece in the description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 16:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/833370#M329429</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-14T16:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time difference between two string datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/833373#M329432</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This isn't a very good answer ... but B8601DT seems happy when the value is just a date and no time component, while E8601DT seems to only work when there is a time component. However, I don't see where the documentation says that.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The difference in the documentation is that B8601dt includes:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-details"&gt;
&lt;DIV id="n1wnkrflw87821n12u7rhw9xzj90" class="xis-topicContent"&gt;
&lt;DIV id="p019zmyymbos42n1v7dw9dasxsr0" class="xis-paragraph"&gt;If the hour, minute, or second values are omitted, SAS uses a value of 0 for the hour, minute, or second.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;but E8601dt does not have a similar piece in the description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That answers the question!!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 16:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-time-difference-between-two-string-datetime/m-p/833373#M329432</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-14T16:40:10Z</dc:date>
    </item>
  </channel>
</rss>

