this is the script I am running
import datetime
# Get the current date
current_date = datetime.datetime.now()
# Initialize a counter
counter = 0
# Define the number of iterations
total_iterations = 730 # for 2 years
while counter < total_iterations:
# Calculate Date2 as Date1 - 15 days
date2 = current_date - datetime.timedelta(days=15)
# Print Date1 and Date2
print("Date1:", current_date.strftime("%Y-%m-%d"))
print("Date2:", date2.strftime("%Y-%m-%d"))
# Update Date1 for the next iteration
current_date = date2 - datetime.timedelta(days=1)
# Increment the counter
counter += 1
I have provide correct alligment to the script. Can someone help regarding this.
Hi @Abhisht
Just set the indentation as below
import datetime
# Get the current date
current_date = datetime.datetime.now()
# Initialize a counter
counter = 0
# Define the number of iterations
total_iterations = 730 # for 2 years
while counter < total_iterations:
# Calculate Date2 as Date1 - 15 days
date2 = current_date - datetime.timedelta(days=15)
# Print Date1 and Date2
print "Date1:", current_date.strftime("%%Y-%%m-%%d")
print "Date2:", date2.strftime("%%Y-%%m-%%d")
# Update Date1 for the next iteration
current_date = date2 - datetime.timedelta(days=1)
# Increment the counter
counter += 1
Try as above and you are fine to get the results
If you find this reply helpful, please consider giving it a LIKE AND
If this reply answers your question or solves your issue, please ACCEPT AS SOLUTION
Thanks,
Srini
Can you share a screenshot of your flow?
its working but its showing empty in the display message
The syntax error is because of the percentage symbols. These are reserved by PAD for variable notation. To pass a literal % to the script, you need to escape it with another %. Try this:
print("Date1:", current_date.strftime("%%Y-%%m-%%d"))
print("Date2:", date2.strftime("%%Y-%%m-%%d"))
Please note, however, that PAD can only return a single value from a Python script. When you have several print statements, you will not get the actual 730 x 2 strings printed out. If you want that, you should in fact append your values to a single string inside the loop and then use a single print statement at the end of the script.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.
WarrenBelz
146,645
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,997
Most Valuable Professional