I am currently writing a script where it's to automate generating reports for end of quarter reports. Part of the naming convention for the folders includes Q1, Q2, Q3, or Q4 based on which quarter it is for based on the date it is generated. So far, my code looks like this:
import arcpy
import datetime
date = datetime.date.today()
quarter = 'Q1' if '2017-01-01' =< str(date) =< '2017-03-31' elif 'Q2' if '2017-04-01' =< str(date) =< '2017-06-30' elif 'Q3' if '2017-07-01' =< str(date) =< '2017-09-30' else 'Q4'
My issue is that I get an output of Q4 when I try
print quarter
. The output generated should have been Q3 as I ran this today (July 10, 2017). If I change the ending of the code to be
'Q4' if '2017-10-01' =< str(date) =< '2017-12-31'
, the result would be a syntax error. What am I doing wrong and how can I fix it but also stored the if conditional in one line and set it equal to the variable quarter?
Solved! Go to Solution.
I agree Alexander, realized that after I had responded to Kevin's approach. As of right now, I have my tool set to the function method you provided. Made notes of the method tat Blake suggested too (that one I don't think you have to alter the code on a yearly basis).
Just glad we could help you out! Now you have a lot of options.
~Alex
Much appreciated! Thank you once again!
While we are on the topic of time.... Richard Fairhurst's blog ... I've saved time in a bottle ...how do i get it back out doing more with... totally forgot about that one.