Field Calculator - DateDiff() function Python Equivalent

14085
2
Jump to solution
10-03-2014 11:25 AM
NickMoylan
New Contributor II

Hello, I have a model that calculates an integer field with the DateDiff() function.  The difference is between an 'expiry_date'(date type) field formatted "mm/dd/yyyy" and the now() function.  I want to export this model to a Python script, however it wont allow the VB function to be used.  It is a large model that I would rather not rewrite, is there python code that I can use in the tool before I export it to a python script in place of the VB to calculate this integer field??

0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Occasional Contributor III

You can use the datetime module.

Code block:

import datetime

Expression:

(datetime.datetime.now() - datetime.datetime.strptime(!field_with_formatted_date!, "%m/%d/%Y")).days

View solution in original post

2 Replies
JasonScheirer
Occasional Contributor III

You can use the datetime module.

Code block:

import datetime

Expression:

(datetime.datetime.now() - datetime.datetime.strptime(!field_with_formatted_date!, "%m/%d/%Y")).days

NickMoylan
New Contributor II

This works great!

Thanks foir the help.

0 Kudos