Hi,
I wrote this python script :
from java.util import Date
now=Date()
now=system.db.dateFormat(now, "yyyy-MM-dd H:mm:ss")
yesterday='now - 1 day'
I would like to calculate variable “yesterday”. I tried a lot of method but it’s not working.
Can you help me please ?
Hi flavien,
You an do this with Java’s Calendar object:
from java.util import Date, Calendar
now = Calendar.getInstance()
now.add(Calendar.DATE, -1)
yesterday = Date(now.getTimeInMillis())
print yesterday
print system.db.dateFormat(yesterday,"yyyy-MM-dd H:mm:ss")
import time
import datetime
yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
print yesterday
In 7.8.0 and later, you can also do this:
print system.date.addDays(system.date.now(), -1)
Not sure why the new system.date.* script functions aren’t in the docs yet… I’ll ping our training dept and see what’s up with that.