I'm trying to set the time in a datetime object in a python script. I've tried using the datetime.replace and also the datetime.combine and neither one will work.
Don't use datetime, use java's built-in objects java.util.Date, it's what ignition's system.date.* functions use.
So then, you can use system.date.setTime | Ignition User Manual
I'm trying to do a manipulation with the dates and I found a way to do that with the python datetime.
I have a start date and end date that may be a month or several months. I need to loop through each day from 6am to 6pm and run another script on each day.
Again: Don't do this with python's datetime, use Java's dates instead.
If you can describe what you're trying to do, we can help you.
But as it is, it's confusing to say the least.
Do you need to run the script once per day ? Then what are the times for ?
Do you have a start and end DATES (not TIMES) ?
Do you have a number of days instead ?
In the end, what is the whole thing supposed to do ?
The start date and end date are picked from a calendar component in vision for a report viewer. The example I gave was just my trying things out in the script console.
If the start date is 1/1/2024 and the end date is 3/31/2024, I need to go through these dates in a script for each day isolating each shift (6am-6pm and 6pm-6am) to get data from several different data sources.
startDate = system.date.parse('2024-01-01 00:00:00')
endDate = system.date.parse('2024-01-10 00:00:00')
dates = iter([system.date.addDays(startDate, n) for n in xrange(system.date.daysBetween(startDate, endDate)+1)])
for date in dates:
do_your_thing(date)
It will work without the iter() function, but if there are a lot of dates, then making an iterator instead of an iterable list will help save memory.