This topic was automatically generated from Slack. You can find the original thread here.
is there a syntax for a date placeholder I can run in a function that mimics something like this: (now() AT TIME ZONE ‘utc’::text)
This topic was automatically generated from Slack. You can find the original thread here.
is there a syntax for a date placeholder I can run in a function that mimics something like this: (now() AT TIME ZONE ‘utc’::text)
In JavaScript, you can get the current date and time in UTC format using the Date
object. Here’s an example of how you can achieve this within a Pipedream component: ```
export default defineComponent({ async run({ steps, $ }) { // Get the current date and time in UTC format const currentDate = new Date().toISOString(); // Your code here, using currentDate as needed return currentDate; }, });
could I do this as an option for a postgresql step?
Yes, you can use a PostgreSQL action to execute a custom query with a date function. Use the “Execute Custom Query” action in your Pipedream workflow. Here’s how to set it up: 1. Search for the PostgreSQL app from the step menu. 2. Select the “Execute Custom Query” action. 3. Connect your PostgreSQL account. 4. In the SQL Query field, enter your query with the date function, for example: ```
SELECT NOW() AT TIME ZONE ‘UTC’;
What if I want to pass new Date().toISOString()
as the value of a prop? How would I do that?
You can set a default value for a prop in your Pipedream component. Here’s an example of how to set the default value of a prop to the current date and time in UTC format using new Date().toISOString()
: export default defineComponent({ props: { currentDate: { type: "string", label: "Current Date", default: new Date().toISOString(), }, }, async run({ steps, $ }) { // Your code here, using this.currentDate as needed return this.currentDate; }, });
In this example, the currentDate
prop will have a default value of the current date and time in UTC format. You can use this.currentDate
within the run
method to access its value.
I don’t want to set a default, I want to pass that as the value of the prop in a step in the Pipedream UI
To pass the value of new Date().toISOString()
as a prop in a step within the Pipedream UI, you can follow these steps: 1. Create a new Pipedream component with a prop for the date value: export default defineComponent({ props: { dateValue: { type: "string", label: "Date Value", }, }, async run({ steps, $ }) { // Your code here, using this.dateValue as needed return this.dateValue; }, });
2. Add this component as a step in your Pipedream workflow. 3. In the Pipedream UI, you’ll see a form field for the “Date Value” prop. 4. Enter {{ new Date().toISOString() }}
as the value for the “Date Value” prop. This will pass the current date and time in UTC format as the value of the dateValue
prop when the step runs. Now, when the step runs, it will use the passed date value in the component code.
Is that what you were trying to do? If you’re using a pre-built Postgres step, passing {{ new Date().toISOString() }}
will evaluate to the current ISO datetime string. In general, you can run any JavaScript inside of the {{ }}
within those fields. We call these fields “props”, which is why you’ll see references to those above.
let me know if you’re trying to do something different
hey Dylan! I think so - I’m trying to use the simple PostgreSQL to do this without another node.js step since it is just modifying one item - not sure if i’ll be able to do it this way?
yes, that syntax looks accurate. That value should return a string like 2023-07-06T21:49:16.812Z
Do I need to make a prop step before this or would it pick this up automatically with that syntax?
for some reason it’s kicking off an Invalid optional chain from new expression
so the cool thing is these pre-built actions are using props behind the scenes, so you’re all good. That example from Pi would help if you were writing code from scratch — you can add props to any code steps.
What you encountered looks like a separate bug. Sharing with the team. For now I’d add a Node.js code step above this step and then reference that value in the Postgres step:
export default defineComponent({
async run({ steps, $ }) {
return new Date().toISOString()
},
});
I’ll share this example with the team and we’ll get that bug fixed
ok makes sense! I’ll build that out as a step and then reference it back thank you so much for your help!