<?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: Handling Date &amp;amp; Time stamps across midnight in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358756#M60886</link>
    <description>&lt;P&gt;The following explains what's wrong. Every row in your data table falls into one of the two situations.&lt;/P&gt;
&lt;P&gt;1) DateTime is on the left side of the interval defined by OnDate and OffDate&lt;/P&gt;
&lt;P&gt;2) DateTime is between OnDate and OffDate.&lt;/P&gt;
&lt;P&gt;The second situation always gives expected answer. The first situation will fail nearly half of the time.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="peng_liu_0-1613268753521.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/30219iA6B25DC64F9DA0F4/image-size/large?v=v2&amp;amp;px=999" role="button" title="peng_liu_0-1613268753521.png" alt="peng_liu_0-1613268753521.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 14 Feb 2021 02:12:45 GMT</pubDate>
    <dc:creator>peng_liu</dc:creator>
    <dc:date>2021-02-14T02:12:45Z</dc:date>
    <item>
      <title>Handling Date &amp; Time stamps across midnight</title>
      <link>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358498#M60859</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I´m working with data from an experiment where light and day has been switched around in a controlled environment.&lt;/P&gt;&lt;P&gt;In this case, over a certain period of time, light is turned on at 10 PM and turned off at 10 AM everyday. For each DateTime value&amp;nbsp;(every 5 min) in this experiment I have created a column where I need to characterise if it´s light or dark.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a script:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( :LightsOnDate &amp;lt; :DateTime &amp;lt;= :LightsOffDate,
	"Light phase",
	"Dark phase"
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When data in DateTime moves past 10 PM it correctly puts in the value "light phase", however when it moves past midnight it changes to "dark phase" again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why is it doing that and how can I fix it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Br Julie&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:26:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358498#M60859</guid>
      <dc:creator>JulieSAppel</dc:creator>
      <dc:date>2023-06-10T23:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date &amp; Time stamps across midnight</title>
      <link>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358519#M60861</link>
      <description>&lt;P&gt;Your formula seems to working correctly. LightOnDate on last three rows is most likely incorrect as light was turned on the previous day?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:11:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358519#M60861</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-02-12T16:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date &amp; Time stamps across midnight</title>
      <link>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358525#M60863</link>
      <description>&lt;P&gt;Given that your on and off times are static, I believe the formula should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Hour( :DateTime - In Hours( 10 ) ) &amp;lt; 12,
	"Dark phase",
	"Light phase"
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One needs to deal with the hour of the day, and the subtracting off of the 10 hours forces the days to align&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:46:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358525#M60863</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-02-12T16:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date &amp; Time stamps across midnight</title>
      <link>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358531#M60864</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/8834"&gt;@JulieSAppel&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;mentions, you have to deal with the time of day issue. I got it to work with the following change to your column formula. I chose the 22 because of the lights always go on at 22:00 hours. But, there are other ways this can be done.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(
	:LightOnDate &amp;lt; :DateTime &amp;lt;= :LightOffDate |
	Date Difference( :DateTime, :LightOnDate, "Hour" ) == 22,
	"Light Pahse",
	"Dark Phase"
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:58:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358531#M60864</guid>
      <dc:creator>SDF1</dc:creator>
      <dc:date>2021-02-12T16:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date &amp; Time stamps across midnight</title>
      <link>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358585#M60866</link>
      <description>&lt;P&gt;I think that you only need the :DateTime value since the light on and light off is always the same. Similar to&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;. If so, this expression is simpler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;t1 = Modulo( :DateTime, In Days( 1 ) );
If( In Hours( 10 ) &amp;lt; t1 &amp;lt;= In Hours( 22 ),
	"Dark",
	"Light"
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 18:16:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358585#M60866</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2021-02-12T18:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date &amp; Time stamps across midnight</title>
      <link>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358756#M60886</link>
      <description>&lt;P&gt;The following explains what's wrong. Every row in your data table falls into one of the two situations.&lt;/P&gt;
&lt;P&gt;1) DateTime is on the left side of the interval defined by OnDate and OffDate&lt;/P&gt;
&lt;P&gt;2) DateTime is between OnDate and OffDate.&lt;/P&gt;
&lt;P&gt;The second situation always gives expected answer. The first situation will fail nearly half of the time.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="peng_liu_0-1613268753521.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/30219iA6B25DC64F9DA0F4/image-size/large?v=v2&amp;amp;px=999" role="button" title="peng_liu_0-1613268753521.png" alt="peng_liu_0-1613268753521.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Feb 2021 02:12:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358756#M60886</guid>
      <dc:creator>peng_liu</dc:creator>
      <dc:date>2021-02-14T02:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date &amp; Time stamps across midnight</title>
      <link>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358819#M60900</link>
      <description>&lt;P&gt;Thanks for all of your replies. I see the issue with midnight, but I just thought that as DateTime is basically just a numerical value that needs to be evaluated whether it is in a range or not, it wouldn´t be a problem but I guess I was wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I see the different solutions working for this specific data but I´m looking for a generic solution (I probably should have mentioned that) that will fit different datasets where LightsOn and LigthsOff are different than what they are here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for other datasets, LightsOn could be at 7 AM and LightsOff at 9 PM meaning that the different periods may also vary in length.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyway to get around this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Br Julie&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 12:06:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358819#M60900</guid>
      <dc:creator>JulieSAppel</dc:creator>
      <dc:date>2021-02-15T12:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date &amp; Time stamps across midnight</title>
      <link>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358936#M60907</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/8834"&gt;@JulieSAppel&lt;/a&gt;&amp;nbsp;, I think you are correct in that you can do the comparison of the date values. I agree with&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;'s response in that the formula you have is correct but the value for LightOnDate might not be.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 17:11:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358936#M60907</guid>
      <dc:creator>Ryan_Gilmore</dc:creator>
      <dc:date>2021-02-15T17:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Handling Date &amp; Time stamps across midnight</title>
      <link>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358958#M60911</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/8834"&gt;@JulieSAppel&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I believe this should work and do it for any time difference between the on/off states.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(
	Modulo( :LightOnDate, In Days( 1 ) ) &amp;gt; Modulo( :DateTime, In Days( 1 ) ) &amp;amp; 	Modulo( :DateTime, In Hours( 1 ) ) == Modulo( :DateTime, In Days( 1 ) ),"Light Phase",
	:LightOnDate &amp;lt; :DateTime &amp;lt;= :LightOffDate, "Light Phase",
	"Dark Phase"
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; Should be independent of whether or not the on/off times are 1 hr, 12 hs, or 6 hrs apart.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I'm not sure how your setup is recording the data, but if it's basically pulling a time stamp from equipment and has some way to record (even if just a Boolean) the state of the equipment, e.g. 0==off and 1==on, then you would only need two columns, one would be the actual day/time column and the other would be the Boolean state of the system and you can set the Value Labels to 0 == "Dark Phase" and 1 == "Light Phase", for example. If you can do it that way, then you wouldn't need to worry about issues of going over midnight or even how long each phase is. Even if there's a user interface button that one clicks to change phases, the program should be able to record the state of the button and feed it to an output table with the date/time data as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!,&lt;/P&gt;&lt;P&gt;DS&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 18:44:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Handling-Date-amp-Time-stamps-across-midnight/m-p/358958#M60911</guid>
      <dc:creator>SDF1</dc:creator>
      <dc:date>2021-02-15T18:44:09Z</dc:date>
    </item>
  </channel>
</rss>

