Hi
I am new to Python and not a programmer. I wish to use the field calculator to subtract an "Expiry Date" from the current date. I have used the following code (which works), but it is using a field containing the current date. How do I change this code so it uses only one field and subtracts from the current date?
Many thanks
Alan
Code
import datetime
def NoDays(d1, d2):
c1 = datetime.datetime.strptime (d1.split () [0], "%Y/%m/%d")
c2 = datetime.datetime.strptime (d2.split () [0], "%Y/%m/%d")
n = (c1 - c2).days
return n
Expression
NoDays( !Expiry! , !Current!)
I am new to Python and not a programmer. I wish to use the field calculator to subtract an "Expiry Date" from the current date. I have used the following code (which works), but it is using a field containing the current date. How do I change this code so it uses only one field and subtracts from the current date?
Many thanks
Alan
Code
import datetime
def NoDays(d1, d2):
c1 = datetime.datetime.strptime (d1.split () [0], "%Y/%m/%d")
c2 = datetime.datetime.strptime (d2.split () [0], "%Y/%m/%d")
n = (c1 - c2).days
return n
Expression
NoDays( !Expiry! , !Current!)