<?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 Get YYYYMMDD String from Date in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-yyyymmdd-string-from-date/m-p/388750#M30736</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a script where the user enters a StartDate and EndDate (via arcpy.GetParameterAsText dialog boxes).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to return strings of those dates in a "YYYYMMDD" format.&amp;nbsp; In another script, I used a snippet to loop through the dates and return a string (CurrentDate) in YYYYMMDD format, but I really don't understand how that function works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any help,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon Mulder&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; from datetime import date from dateutil.rrule import rrule, DAILY import time&amp;nbsp; StartDate = arcpy.GetParameterAsText(0) EndDate = arcpy.GetParameterAsText(0) print StartDate strStartDate = "YYYYMMDD"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #How do I get this format?&amp;nbsp;&amp;nbsp; for dt in rrule(DAILY, dtstart=DateStart, until=DateEnd): &amp;nbsp;&amp;nbsp;&amp;nbsp; CurrentDate = dt.strftime("%Y%m%d")&amp;nbsp; print "Done."&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 22 Dec 2013 09:14:20 GMT</pubDate>
    <dc:creator>JonathanMulder</dc:creator>
    <dc:date>2013-12-22T09:14:20Z</dc:date>
    <item>
      <title>Get YYYYMMDD String from Date</title>
      <link>https://community.esri.com/t5/python-questions/get-yyyymmdd-string-from-date/m-p/388750#M30736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a script where the user enters a StartDate and EndDate (via arcpy.GetParameterAsText dialog boxes).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to return strings of those dates in a "YYYYMMDD" format.&amp;nbsp; In another script, I used a snippet to loop through the dates and return a string (CurrentDate) in YYYYMMDD format, but I really don't understand how that function works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any help,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon Mulder&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; from datetime import date from dateutil.rrule import rrule, DAILY import time&amp;nbsp; StartDate = arcpy.GetParameterAsText(0) EndDate = arcpy.GetParameterAsText(0) print StartDate strStartDate = "YYYYMMDD"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #How do I get this format?&amp;nbsp;&amp;nbsp; for dt in rrule(DAILY, dtstart=DateStart, until=DateEnd): &amp;nbsp;&amp;nbsp;&amp;nbsp; CurrentDate = dt.strftime("%Y%m%d")&amp;nbsp; print "Done."&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 22 Dec 2013 09:14:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-yyyymmdd-string-from-date/m-p/388750#M30736</guid>
      <dc:creator>JonathanMulder</dc:creator>
      <dc:date>2013-12-22T09:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Get YYYYMMDD String from Date</title>
      <link>https://community.esri.com/t5/python-questions/get-yyyymmdd-string-from-date/m-p/388751#M30737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jon,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure how the user is entering the start and end date, but if they enter it as '12/23/2013', you could use the dateutil module to convert this to YYYYMMDD.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import dateutil from dateutil import parser&amp;nbsp; startDate = '12/23/2013'&amp;nbsp; print parser.parse(startDate).strftime('%Y%m%d')&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 10:05:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-yyyymmdd-string-from-date/m-p/388751#M30737</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-12-23T10:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: Get YYYYMMDD String from Date</title>
      <link>https://community.esri.com/t5/python-questions/get-yyyymmdd-string-from-date/m-p/388752#M30738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks very much for showing me the parser utility!&amp;nbsp; I incorporated it into my test code below and it works!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os

from datetime import date
from dateutil.rrule import rrule, DAILY
import time
from dateutil import parser

DateStart = arcpy.GetParameterAsText(0)
arcpy.AddMessage(DateStart)
strDateStart = parser.parse(DateStart).strftime('%Y%m%d')
arcpy.AddMessage(strDateStart)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon Mulder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;California Department of Water Resources&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:51:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-yyyymmdd-string-from-date/m-p/388752#M30738</guid>
      <dc:creator>JonathanMulder</dc:creator>
      <dc:date>2021-12-11T17:51:06Z</dc:date>
    </item>
  </channel>
</rss>

