Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Dynamic default variable value for DateTime data types


is it possible to declare a dynamic default variable value for the DateTime data format - e.g. now()?
If we leave the default value empty and reading that empty value within a Python script, the data type becomes <None> and we have to create a Python DateTime Object which leads to errors with context.updateVariable():

Example (var 'load_date_from' declared as DateTime type with no default value set):

import datetime

if load_date_from is None:
today ='%Y/%m/%d')
print today
context.updateVariable('load_date_from', today)

This causes an error:
java.text.ParseException: java.text.ParseException: Variable [load_date_from] of type [DATETIME] failed to parse value [2017/03/31]. in <script> at line number 9

I know that I could use the Text data type to handle the date parsing and so on, but it would be nice to use correct data types and use Matillion's DateTime Methods on them ;-)

Thanks in advance

1 Community Answers

Matillion Agent  

Ian Funnell —

Hi Olli,

I agree, it would be nice if the updateVariable was overloaded to accept dates and times, and also if variables could have dynamic default values.

But you can apply dynamic defaults in many places without using variables: by just adding in a literal JavaScript expression instead.

So for example in a Table Input transformation component, you could set the “Table Name” to:

tab_${new Date().getFullYear().toString()}

Then it will try to read from a table named tab_2017, where the 2017 part is generated at runtime.

Best regards,

Post Your Community Answer

To add an answer please login