Subtract time to date


I wrote this python script :

from java.util import 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.timedelta(days=1) print yesterday

In 7.8.0 and later, you can also do this:

print, -1)

Not sure why the new* script functions aren’t in the docs yet… I’ll ping our training dept and see what’s up with that.