cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Javascript example for date/time manipulation in script snap?

doug_fossler
New Contributor

I am attempting to write javascript for a script snap to manipulate dates, times, and date/times. I am having issues getting a date field plus a separate time field parsed as a DateTime and further having issues when I need to add a duration of time to the DateTime. Are there any examples of this somewhere?

Doug

13 REPLIES 13

punchInDate is in โ€œyyyy-MM-ddโ€
punchInTime is in โ€œHH:mmโ€

punchIn should be something like โ€œMM/dd/yyyy HH:mmโ€, or โ€œyyyy-MM-dd HH:mmโ€, or โ€œMMddyyyyHHmmโ€, etc.

@doug.fossler
Use this-
$punchInDate.toLocaleDateString(โ€˜{โ€œformatโ€:โ€œyyyy-MM-dd HH:mmโ€}โ€™

if punchInDate is coming as date field , if itโ€™s coming as String then 1st do Date.parse($punchInDate), then use formater in mapper snap

I am not doing this inside a mapper snap, i am attempting to do this in javascript inside a script snap on purpose.

@doug.fossler

use mapper only. Why need to have script snap? always trying to ignore script as much as possible.

doug_fossler
New Contributor

My use case will not allow this to be handled in a mapper. Unless you can tell me how to edit multiple docs based on the prior edits of said docs? I am aware of arrayโ€™s but they would not solve the problem.