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

@doug.fossler

Please share your json data , which are the input of your script.

doug_fossler
New Contributor

An easy example (i.e. only three docs).

[
    {
        "groupBy": {
            "resourceId": "999000641",
            "EventDate": "07/24/2017"
        },
        "group": [
            {
                "resourceId": "999000641",
                "punchInDate": "07/24/2017",
                "EventDate": "07/24/2017",
                "break": null,
                "costCenter": "54770",
                "timeType": "1",
                "punchInTime": "06:53",
                "resourceLastName": "brown",
                "$rowCountPernull": 1,
                "WorkedHours": "4",
                "punchOutTime": "10:53",
                "siteId": "500",
                "punchOutDate": "07/24/2017",
                "resourceFirstName": "Test",
                "yalePayCode": "1",
                "optPayTypeId": 1
            },
            {
                "resourceId": "999000641",
                "punchInDate": "07/24/2017",
                "EventDate": "07/24/2017",
                "break": null,
                "costCenter": "54620",
                "timeType": "1",
                "punchInTime": "10:53",
                "resourceLastName": "brown",
                "$rowCountPernull": 2,
                "WorkedHours": "3.5",
                "punchOutTime": "14:23",
                "siteId": "500",
                "punchOutDate": "07/24/2017",
                "resourceFirstName": "Test",
                "yalePayCode": "1",
                "optPayTypeId": 1
            },
            {
                "resourceId": "999000641",
                "punchInDate": "07/24/2017",
                "EventDate": "07/24/2017",
                "break": null,
                "costCenter": "64990",
                "timeType": "1",
                "punchInTime": "14:23",
                "resourceLastName": "brown",
                "$rowCountPernull": 3,
                "WorkedHours": "5.25",
                "punchOutTime": "19:38",
                "siteId": "500",
                "punchOutDate": "07/24/2017",
                "resourceFirstName": "Test",
                "yalePayCode": "1",
                "optPayTypeId": 1
            }
        ]
    }
]```

@doug.fossler
Use the pipeline. Ignore json generator part and go ahead the changes. Let me know the result.

DateConvertion_2018_06_29.slp (6.6 KB)

doug_fossler
New Contributor

I can do what your pipeline does, the issue is when i have a sub-group of multiple docs that require editing of their fields based on prior and former docs. Unfortunately the attempt to work around the problem does not resolve the problem. It seems that it is not possible to combine two strings and create a date-time in a script snap.