Select to view content in your preferred language

Field Calculator - DateDiff() function Python Equivalent

14366
2
Jump to solution
10-03-2014 11:25 AM
NickMoylan
Deactivated User

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
Esri Alum

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
Esri Alum

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
Deactivated User

This works great!

Thanks foir the help.

0 Kudos