Skip to main content
Solved

How do I set a date field to NOW() in automation?

  • May 4, 2023
  • 6 replies
  • 452 views

Ruchika_Abbi1
Forum|alt.badge.img+17

I want to set a Date field to the current date time in an automation. I tried using a formula field (with NOW()) from a previous step in the automation to set this Date field but the automation fails with the error;
Field "Date" cannot accept the provided value: Could not convert string to date.

No amount of formatting of the formula field is helping. 

Best answer by Alexey_Gusev

Hi,
Using NOW() to set current time, you should be aware that it updates every 5-10 minutes. So, the minute value won't be precise to a single minute. Also, it can cause delay of triggering automation.
I would set one-liner script step and use output for field value in next Update step. Precision+No delay+No extra column.
 

output.set('now',new Date().toISOString())

 here, 'now' is just a variable name, you can change it

6 replies

TheTimeSavingCo
Forum|alt.badge.img+31

Hmm, weird.  Could you provide screenshots of your table and automation setup, or access to an example base where you're encountering this issue?

I was able to use an automation to paste the value from a formula field with "NOW()" into a Date field without that error and so I think my setup's different from yours:


Link to base


Alexey_Gusev
Forum|alt.badge.img+25
  • Brainy
  • 1261 replies
  • Answer
  • May 4, 2023

Hi,
Using NOW() to set current time, you should be aware that it updates every 5-10 minutes. So, the minute value won't be precise to a single minute. Also, it can cause delay of triggering automation.
I would set one-liner script step and use output for field value in next Update step. Precision+No delay+No extra column.
 

output.set('now',new Date().toISOString())

 here, 'now' is just a variable name, you can change it


Ruchika_Abbi1
Forum|alt.badge.img+17
  • Author
  • Inspiring
  • 43 replies
  • May 8, 2023

Hi,
Using NOW() to set current time, you should be aware that it updates every 5-10 minutes. So, the minute value won't be precise to a single minute. Also, it can cause delay of triggering automation.
I would set one-liner script step and use output for field value in next Update step. Precision+No delay+No extra column.
 

output.set('now',new Date().toISOString())

 here, 'now' is just a variable name, you can change it


This worked, thanks!


Forum|alt.badge.img+1
  • New Participant
  • 1 reply
  • June 6, 2023

Thanks for the solution


Karl_at_Easy_La
Forum|alt.badge.img+15

Hi,
Using NOW() to set current time, you should be aware that it updates every 5-10 minutes. So, the minute value won't be precise to a single minute. Also, it can cause delay of triggering automation.
I would set one-liner script step and use output for field value in next Update step. Precision+No delay+No extra column.
 

output.set('now',new Date().toISOString())

 here, 'now' is just a variable name, you can change it


Thanks for this solution - simple, efficient and genuis! 🙂


clabonty
Forum|alt.badge.img+8
  • Inspiring
  • 5 replies
  • June 26, 2024

Hi,
Using NOW() to set current time, you should be aware that it updates every 5-10 minutes. So, the minute value won't be precise to a single minute. Also, it can cause delay of triggering automation.
I would set one-liner script step and use output for field value in next Update step. Precision+No delay+No extra column.
 

output.set('now',new Date().toISOString())

 here, 'now' is just a variable name, you can change it


This script is great, very helpful for some of my automated emails! But can you help me refine the formatting a bit for my use?

Here's my current code:

 

 

output.set('now',new Date().toLocaleString("en-US", {timeZone: "America/Los_Angeles"}))

 

 

This outputs: 6/25/2024, 5:15:25 PM

I wanted the date/time to be formatted differently, so I'm using toLocaleString instead of toISOString. And I was able to properly set the timezone as I desire... however I can't figure out how to remove the seconds. Everything I've tried so far generates an error.

I'm a bit of a Java newbie, so any help is appreciated!

EDIT: I figured it out, here's my current code which has a nice clean output.

output.set('now', new Date().toLocaleString("en-US", { timeZone: "America/Los_Angeles", month: 'numeric', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true }).replace(',', '').replace(' AM', 'AM').replace(' PM', 'PM'));