Tech note 20_02 - Calculating Expiry Dates

Calculating Expiry Dates

Technote 20/02

Date: November 6th, 2020

Author: Craig Bechelli

Applicable Products: CardExchange® Producer

Calculating Expiry Dates

 

To calculate expiry dates in CardExchange Producer, you can use a Python script like the one below:

 

import datetime

from datetime import date

def expiry():

#Number of years to add

years = 3

#Get todays date

today = date.today()

#Date for testing

#today = date(2016,2,29)

return addYears(today, years).strftime ('%d/%m/%Y')

def addYears(d, years):

try:

#Return same day of the current year

return d.replace(year = d.year + years)

except ValueError:

#If not same day, it will return other, i.e. February 29 to March 1 etc.

return d + (date(d.year + years, 1, 1) - date(d.year, 1, 1))

 

 

 

 

If you load the designer you can paste this into the functions tab as below:

 

 

 

 

 

 

Then on a visible item, or on a storage item you can choose the script option as the source an call the script expiry() like this:

 

 

You can edit the script and change the years variable to any other value you need.