Brain Teaser d'jour....
I have a data table that has a date field. The values in the date field are only month/day/year (5/7/2018) and the client wants to keep the date portion and then get a Hours:Minutes:Seconds tacked on to it so the final value looks like:
5/7/2018 4:20:20 PM
The H:M:S are going to be 'phony'; that is I'll just generate them in a loop using a combination of time.now(), strftime and time.sleep(); that's not the problem.
It's getting that new H:M:S together with the existing M/D/Year back into the datefield that is the teaser. Been looking at strptime, and that gets pretty ugly pretty fast. Just wondering if there might be an easier way?
Dan Patterson
Darren Wiens
Joshua Bixby
This generates H:M:S at one second interval:
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"AddTimeToSampleDate"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'*'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> millerTime <SPAN class="operator token">=</SPAN> datetime<SPAN class="punctuation token">.</SPAN>now<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>strftime<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'%I:%M:%S %p'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">print</SPAN> millerTime
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> time<SPAN class="punctuation token">.</SPAN>sleep<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">08</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">09</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">10</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">11</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">12</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">13</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">14</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">15</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">16</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">17</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">18</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">19</SPAN> PM
<SPAN class="number token">03</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">47</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">20</SPAN> PM
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>