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

Variable

Hi,

I want to add current_date into filename... It get from system time...

{ EX : abc_2018-06-13 00:27:27 }

Thanks,

Mathan.

7 Community Answers

Matillion Agent  

Kalyan Arangam —

Hi mathan,

Assuming you have a datetime variable called dt, here’s an expression to calculate today’s date, format it and append to a filename.

Filename_${dt.now().format(“yyyy/MM/dd”))}.csv

Please see the following link on using date and time functions with variables. The examples assume you have a job/project variable called dt of type datetime.

https://redshiftsupport.matillion.com/customer/en/portal/articles/2711553-date-and-time-methods?b_id=8915

You may also use a python script to calculate the appropriate date value and store in a variable.

Hope that helps

Best
Kalyan


Mathan Selvaraj —

Hi Kalyan,

How to set datetime variable into environment variable...

Thanks,

Mathan


Matillion Agent  

Kalyan Arangam —

Hi Mathan,

You may create a variable under “Project→Manage Environment Variables”

Please see the following link for information on variables and usage.

https://redshiftsupport.matillion.com/customer/en/portal/articles/2037630-variables

Best
Kalyan


Mathan Selvaraj —

Hi Kalyan,

I'm passing that parameter to environment variable...

I get filename like :: filename_${dt.now().format("yyyy-MM-dd")}.csv

Thanks,

Mathan


Matillion Agent  

Kalyan Arangam —

The only reasons i can think of is when the variable dt is not declared or you are providing the Expression under Default Value.

Please check the following -
- Have you declared an environment a variable dt of type datetime
- The expression you’ve provided should be under component properties and not under default value of a variable.

Best
Kalyan


Kimo Arends —

For community meanings (if someone would encouter this again):

Another reason to get a literally filename with ${dt.now().format("yyyy-MM-dd")} in it, is when you have declared the variable "dt" as datetime, but you 'forgot' to put a default value for this variable....
Then Matillion does not know what to do with it, and just puts it as a literal filename instead of calculating the right date first...

ALL variables declared in Matillion always NEED to have a default value, otherwise strange things happen

@matillion: this should really be resolved some day; i've had the strangest errors because of a default not set for a variable...


Matillion Agent  

Ian Funnell —

Thanks for the message, Kimo.

Agreed about default values.

Some other notes on variables:

  • Matillion always uses the variable’s default value for validation.
  • Default values are specific to an Environment. If you have created more than one Environment, you will need to specify a default value for every Environment.
  • Variables can be updated at runtime, meaning that a component which failed validation may nevertheless still run successfully.

If you need to set variables dynamically at runtime, use a Python Script component in Jython mode.

If you’re setting a date or timestamp then it’s often best to use a Text datatype (rather than a DateTime), since you can then explicitly control the format and the timezone. For example, to have a variable updated to today’s date, you could use the following Python script:

from datetime import datetime

context.updateVariable('updatedtm', "{:%Y-%m-%d}".format(datetime.now()))

print updatedtm

Best regards,
Ian

Post Your Community Answer

To add an answer please login