Skip to content
Advertisement

Passing parameter through function

I needed SQL-like DATEADD(https://learn.microsoft.com/en-us/sql/t-sql/functions/dateadd-transact-sql?view=sql-server-ver15) function to avoid using multiple if statements.

This is what I currently have:

JavaScript

This is what I’m trying to achieve (to pass INTERVAL argument to dateadd function that would change parameter of relativedelta to days,months,years etc.):

JavaScript

Advertisement

Answer

That’s not how it’s done. Try this:

JavaScript

Basically, you have to create a dictionary with parameter name as the key and parameter’s value as the key’s value. And then use ** to unpack the value in the function’s parameter.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement