PYDATE( ) function

Returns a date value calculated by a function in a external Python script. Data processing in Python is external to Analytics.

Syntax

PYDATE("PyFile,PyFunction" <, field|value <,...n>>)

Parameters

Name Type Description
PyFile,PyFunction

character

The name of the Python script to run followed by a comma and then the name of the function that returns the value:

 "myScript,myFunction"

When specifying the Python script, omit the file extension. The function you call may call other functions within the script or within other scripts, however all scripts that run must be placed inside a folder in the PYTHONPATH system environment variable prior to running.

For more information, see Configuring Python for use with Analytics.

Note

Your PyFunction must return a Python datetime.date object.

field |value <,...n>

optional

character

numeric

datetime

logical

This list of fields, expressions, or literal values to use as arguments for the Python function. The values are passed into the function you call in the order you specify them.

You may include as many arguments as necessary to satisfy the function definition in the Python script.

Note

Use the ALLTRIM() function to remove any leading or trailing spaces from character input: ALLTRIM(str). For more information, see ALLTRIM( ) function.

Output

Datetime.

Examples

Basic examples

Returns `20160630`:

PYDATE('hello,due_date', `20160531`, 30)

External Python script that accepts a date and a grace period as a number of days and calculates the date the invoice is due. For an invoice date of 2016-05-31 and a period of 30 days: "2016-06-30":

#! python
from datetime import timedelta

def due_date(inv_date, period):
    return(inv_date + timedelta(period))

Advanced examples

Defining a computed field

Defines a computed field in the Ap_Trans table using the Python script that calculates due date:

OPEN Ap_Trans
DEFINE FIELD due_date COMPUTED 
WIDTH 27
    PYDATE( "hello,due_date" ,Invoice_Date, Pay_Period)
ACL Scripting Guide 14.1