Date Calculation
I want to have one field that is a date and time, and I want to create a calculated field that adjusts that date and time by -11 hour. How would I write this in the calculation field?
-
Hi, Rainer. Thanks for the suggestion. My calculation isn't generating the correct hours based on that code.
I have used: moment(@datefield).subtract(1, 'hour').format('MMM DD YYYY HH:MM')
and also: moment(@datefield).lang('en').subtract(1, 'hour').format('YYYY-MM-DD h:mm a')Neither returns the expected value. Can you help?
-
Thanks, Rainer, for replying. :)
My referenced field is a Date field with a start time only in typical Podio format (eg. Mon 2 February 2015, 09:00).
The calculated field formatting is perfect but the hour calculation is off.
- My calculated field returns Feb 02 2015 00:02 and 2015-02-02 12:00 am respectively.
- I would expect to see Feb 02 2015 08:00 and 2015-02-02 08:00 am. -
Hi Heather,
if you want to display the result as a text use:
moment(@dateField).tz('America/New_York').format("MMM DD YYYY hh:mm a z")
result: Feb 02 2015 08:00 am EST (z shows the timezone)
If you want to display it in date format (like a date field) use:
moment(@dateField).subtract(6,'hours').toDate()
result: date and time in your usual date format (maybe you have to changed the value t0 be substracted; but be careful: It doesn't consider automatically DST changes)
Rainer
-
Hi Rainer,
There seems to be an issue when using your script:
The type of result changed from number to date.
When using: moment(@dateField).subtract(6,'hours').toDate()
Especially the .toDate() part I guess.Removing it results with this error: The script returned an unsupported result type
Any ideas?
-
Hi Jonathan,
once saved calculation fields keep their format (number, text, date), it's fixed by saving. I assume, you have saved your calculation field when it had a number as result. You can't change that, you have to create a new fresh calculation field. If you want the result displayed as date use .toDate(), if as text use .format("your wanted format ") ; define the format inbetween the quotation marks (s. examples in the other postings)
Rainer
rg@delos-consulting.com
Please sign in to leave a comment.
Comments
11 comments