<?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: adding hours in date filed to get the final date python scripts in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224565#M17320</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;hello everyone.&lt;BR /&gt;i am using arcgis 10 and now a days working on network analyst. i got struck in a problem. network analyst is good to calculate the final date for a route on the basis of timewindow start. but my application got a formula that calculates some additional hours for a defined route. i have created a attribute table where i import the start date and then a blank column for final date which i want to populate with a python scripts that adding start date plus no hours gives the results.&lt;BR /&gt;e.g&lt;BR /&gt;3/4/2013 10:23 AM + 36:00 hr =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; final date with time&lt;BR /&gt;&lt;BR /&gt;any vb python script would be a good one&amp;nbsp; for&lt;BR /&gt;THANKS&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; i request readers if they have any general kind of idea, please shere, its highly valueable for me. any solution can be implemented &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if available. reply please&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Apr 2013 02:31:40 GMT</pubDate>
    <dc:creator>nadeemfareed</dc:creator>
    <dc:date>2013-04-26T02:31:40Z</dc:date>
    <item>
      <title>adding hours in date filed to get the final date python scripts</title>
      <link>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224564#M17319</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;hello everyone.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;i am using arcgis 10 and now a days working on network analyst. i got struck in a problem. network analyst is good to calculate the final date for a route on the basis of timewindow start. but my application got a formula that calculates some additional hours for a defined route. i have created a attribute table where i import the start date and then a blank column for final date which i want to populate with a python scripts that adding start date plus no hours gives the results.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;e.g&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3/4/2013 10:23 AM + 36:00 hr =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; final date with time&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;any vb python script would be a good one&amp;nbsp; for&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;THANKS&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Apr 2013 04:12:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224564#M17319</guid>
      <dc:creator>nadeemfareed</dc:creator>
      <dc:date>2013-04-25T04:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: adding hours in date filed to get the final date python scripts</title>
      <link>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224565#M17320</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;hello everyone.&lt;BR /&gt;i am using arcgis 10 and now a days working on network analyst. i got struck in a problem. network analyst is good to calculate the final date for a route on the basis of timewindow start. but my application got a formula that calculates some additional hours for a defined route. i have created a attribute table where i import the start date and then a blank column for final date which i want to populate with a python scripts that adding start date plus no hours gives the results.&lt;BR /&gt;e.g&lt;BR /&gt;3/4/2013 10:23 AM + 36:00 hr =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; final date with time&lt;BR /&gt;&lt;BR /&gt;any vb python script would be a good one&amp;nbsp; for&lt;BR /&gt;THANKS&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; i request readers if they have any general kind of idea, please shere, its highly valueable for me. any solution can be implemented &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if available. reply please&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Apr 2013 02:31:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224565#M17320</guid>
      <dc:creator>nadeemfareed</dc:creator>
      <dc:date>2013-04-26T02:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: adding hours in date filed to get the final date python scripts</title>
      <link>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224566#M17321</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This sounds like a python question, so I have moved it to the python forum.&amp;nbsp; I hope you find your answer!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Apr 2013 14:13:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224566#M17321</guid>
      <dc:creator>MelindaMorang</dc:creator>
      <dc:date>2013-04-26T14:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: adding hours in date filed to get the final date python scripts</title>
      <link>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224567#M17322</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just as an example of how you might use the timedelta object, so you will have to decide how to implement it.&amp;nbsp; Below d1 is a string object representation of the date (I wasn't sure what field type was in your attribute table), so it shows this conversion but you may not necessarily need that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcpy
import datetime
import timedelta

d1 = '3/4/2013 10:23'
d1frmt = datetime.datetime.strptime(d1, "%m/%d/%Y %H:%M")

addhours = 36
dt = datetime.timedelta(hours = addhours) 
later = d1frmt + dt

arcpy.AddMessage(str(later))

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;output date "later" is printed as: 2013-03-05 22:23:00&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:56:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224567#M17322</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T10:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: adding hours in date filed to get the final date python scripts</title>
      <link>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224568#M17323</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;James Crandall has given a very good answer on how to manipulate dates in Python.&amp;nbsp; I would add a couple of things.&amp;nbsp; First, don't try to import timedelta.&amp;nbsp; That will raise an exception.&amp;nbsp; But you don't need it, since it's part of datetime, so just leave that out and James's code will work perfectly.&amp;nbsp; Second, if you want to re-create a string with the same, original format from your new datetime object, simply add this line to the bottom of James's code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;new_datestr = later.strftime("%m/%d/%Y %H:%M")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Apr 2013 16:50:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224568#M17323</guid>
      <dc:creator>MikeHunter</dc:creator>
      <dc:date>2013-04-29T16:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: adding hours in date filed to get the final date python scripts</title>
      <link>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224569#M17324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thanks for answer. but in this script just one date or time is given to be automated. my problem is bit complicated. i have two columns in my attribute table (Start_time, Total_time). another blank column with alis Finish_Time. I want to add these two to get finish_time column automated. remember the total time is in hours format not in date format.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;e.g..&lt;/SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;Start_time+Total_time = finish_time&lt;/STRONG&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 May 2013 03:50:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224569#M17324</guid>
      <dc:creator>ShahbazBaig</dc:creator>
      <dc:date>2013-05-03T03:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: adding hours in date filed to get the final date python scripts</title>
      <link>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224570#M17325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; thanks for answer. but in this script just one date or time is given to be automated. my problem is bit complicated. i have two columns in my attribute table (Start_time, Total_time). another blank column with alis Finish_Time. I want to add these two to get finish_time column automated. remember the total time is in hours format not in date format.&amp;nbsp; &lt;BR /&gt;e.g..&amp;nbsp; &lt;BR /&gt; &lt;STRONG style="color: &amp;quot;#FF0000&amp;quot;;"&gt;Start_time+Total_time = finish_time&lt;/STRONG&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Please be VERY specific here. What are the exact field types for all 3 fields? (I don't quite understand what your "Total_time" field type is).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just tested the code below and it updates field "finish_time" just fine by adding "Total_time" field to the "Start_time" field, with the output as a new datetime. However, it is important to know what the field types are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Start_time: Date&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Total_time: Short Integer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;finish_time: Date&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import datetime import timedelta&amp;nbsp; fc = r"H:\Documents\ArcGIS\Default.gdb\TimeDelta" cursor = arcpy.UpdateCursor(fc) for row in cursor: &amp;nbsp; startdate = row.Start_time &amp;nbsp; totaltime = row.Total_time &amp;nbsp; upddate = datetime.timedelta(hours = totaltime) &amp;nbsp; later = startdate + upddate &amp;nbsp;&amp;nbsp; &amp;nbsp; row.setValue("finish_time", later) &amp;nbsp; cursor.updateRow(row) &amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 May 2013 11:40:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224570#M17325</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-05-03T11:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: adding hours in date filed to get the final date python scripts</title>
      <link>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224571#M17326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;dear members &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; here i have been asked. what is the total time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;here total time is numer of hours&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 06:46:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224571#M17326</guid>
      <dc:creator>nadeemfareed</dc:creator>
      <dc:date>2013-09-12T06:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: adding hours in date filed to get the final date python scripts</title>
      <link>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224572#M17327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;dear members &lt;BR /&gt; here i have been asked. what is the total time.&lt;BR /&gt;here total time is numer of hours&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That is not specific enough answer.&amp;nbsp; What FIELD TYPE is it?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I assumed in my last post it is INTEGER, which would be an appropriate choice.&amp;nbsp; See above for your solution.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 10:06:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224572#M17327</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-09-12T10:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: adding hours in date filed to get the final date python scripts</title>
      <link>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224573#M17328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import datetime&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fc = r"H:\Documents\ArcGIS\Default.gdb\TimeDelta"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cursor = arcpy.UpdateCursor(fc)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for row in cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; startdate = row.Start_time&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; totaltime = row.Total_time&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; upddate = datetime.timedelta(hours = totaltime)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; later = startdate + upddate&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; row.setValue("finish_time", later)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; cursor.updateRow(row)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;its excellent script. just import.timedelta is not required.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;well done heros&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Sep 2013 02:41:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hours-in-date-filed-to-get-the-final-date/m-p/224573#M17328</guid>
      <dc:creator>nadeemfareed</dc:creator>
      <dc:date>2013-09-19T02:41:25Z</dc:date>
    </item>
  </channel>
</rss>

