Date conversion works, except for one field

Date conversion from seconds to yyyy-MM-dd works inconsistently.

I have a platform that stores dates in unix format. Number of seconds since epoch, or, number of seconds since 1/1/1970.

The field holds a string, example given:

{
    "date_enroll":  "1557767588"
}

If I hardcode the number, it works.

If I try to reference the information, it errors out.

I have tried various versions, but it hasnt liked any of them. Another field with a date in it works just fine. I’m using this expression in a set node to convert the date.

{{ DateTime.fromSeconds($json.mosyle.date_last_beat, {zone: 'utc'}).toFormat('yyyy-MM-dd HH:mm') }}

That one works, but this one returns ‘undefined.’

{{ DateTime.fromSeconds($json.mosyle.date_enroll, {zone: 'utc'}).toFormat('yyyy-MM-dd HH:mm') }}

The kicker is if I hard code the value, it works. So I feel it’s something to do with the expression, but the expression is the same except for the reference.

Example of working hard coded value:

"value": "{{ $json.mosyle.date_enroll }}"

What is the error message (if any)?

Various errors. Many irrelevant because it’s the web site telling me my data is in the wrong format.

Please share your workflow

This is the input JSON.


{
{
    "mosyle": {
      "deviceudid": "0A11E88C-B0B2-5CA8-8A1D-193A06B5EBA5",
      "total_disk": 245,
      "os": "macOS 15.3.1",
      "serial_number": "C02FP2Y6Q05N",
      "device_name": "CamilleP MBP M1",
      "device_model": "MacBookPro17,1",
      "battery": "0.31",
      "osversion": "15.3.1",
      "date_info": "1742411444",
      "carrier": null,
      "roaming_enabled": null,
      "isroaming": null,
      "imei": null,
      "meid": null,
      "available_disk": 88,
      "wifi_mac_address": "A0:78:17:AB:60:8C",
      "bluetooth_mac_address": "A0:78:17:AD:78:20",
      "is_supervised": "1",
      "date_app_info": "1742406757",
      "date_last_beat": "2025-03-19 19:10",
      "date_last_push": null,
      "status": "INSTALLED",
      "isActivationLockEnabled": "0",
      "isDeviceLocatorServiceEnabled": null,
      "isDoNotDisturbInEffect": null,
      "isCloudBackupEnabled": null,
      "IsNetworkTethered": null,
      "needosupdate": null,
      "productkeyupdate": null,
      "device_type": "COMPUTER",
      "lostmode_status": "DISABLED",
      "is_muted": "0",
      "date_muted": null,
      "activation_bypass": null,
      "date_media_info": null,
      "tags": "fv",
      "is_deleted": "0",
      "iTunesStoreAccountHash": "q+Nb9uePflsH6PrML9b/Q5BVh+k=",
      "iTunesStoreAccountIsActive": "1",
      "date_profiles_info": "1742406844",
      "ethernet_mac_address": "a0:78:17:ab:60:8c",
      "model_name": "MacBook Pro",
      "LastCloudBackupDate": null,
      "SystemIntegrityProtectionEnabled": "1",
      "BuildVersion": "24D70",
      "LocalHostName": "camillep-mbp-m1",
      "HostName": "camillep-mbp-m1.local",
      "OSUpdateSettings": "{\"AutoCheckEnabled\":true,\"AutomaticAppInstallationEnabled\":true,\"AutomaticOSInstallationEnabled\":false,\"AutomaticSecurityUpdatesEnabled\":true,\"BackgroundDownloadEnabled\":true,\"CatalogURL\":\"https:\\/\\/swscan.apple.com\\/content\\/catalogs\\/others\\/index-15-14-13-12-10.16-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog.gz\",\"IsDefaultCatalog\":true,\"PreviousScanDate\":\"2025-03-19T17:52:40Z\"}",
      "ActiveManagedUsers": "[\"AC08975E-3AFD-467B-9FB9-F0BBA869931E\"]",
      "location": null,
      "CurrentConsoleManagedUser": "camillepinsonnault",
      "date_printers": "1742406765",
      "AutoSetupAdminAccounts": "[{\"GUID\":\"A9AC853B-9CB5-4EA2-8D17-D2C5822C9847\",\"shortName\":\"jamfadmin\"}]",
      "appleTVid": null,
      "asset_tag": null,
      "ManagementStatus": "{\"EnrolledViaDEP\":true,\"IsActivationLockManageable\":true,\"IsUserEnrollment\":false,\"UserApprovedEnrollment\":true}",
      "OSUpdateStatus": null,
      "AvailableOSUpdates": null,
      "percent_disk": "0.35918367346939",
      "idusermosyle": null,
      "idaccount": "1",
      "status_login": "LOGGED",
      "date_lastlogin": "1728406543",
      "date_checkin": "1728406540",
      "date_enroll": "1728406543",
      "date_checkout": null,
      "date_kinfo": "1742411444",
      "enrollment_type": "GENERAL",
      "userid": null,
      "username": null,
      "useremail": null,
      "usertype": null,
      "device_model_name": "MacBook Pro (13-inch, M1, 2020)",
      "has_password": null,
      "TimeZone": null,
      "activation_bypass_mdm": null,
      "cpu_model": "Apple M1",
      "hasvpn": "Yes",
      "installed_memory": "16",
      "vpn_status": "Disconnected",
      "latitude": null,
      "longitude": null,
      "open_direct_device_link": "https://mymsp.mosyle.com/#device_d_1_0A11E88C-B0B2-5CA8-8A1D-193A06B5EBA5",
      "ServiceSubscriptions": null,
      "DeviceAttestationStatus": "Compliant",
      "CustomDeviceAttributes": "[{\"Name\":\"No FV Key Escrowed\",\"CustomAttributeUniqueID\":\"custom_cc_No_FV_Key_Escrowed\",\"Value\":\"FileVault is On. Key Set to be Escrowed to: ClearlyRated will store your FileVault Recovery Key.\"},{\"Name\":\"Escrow Buddy authdb Enabled\",\"CustomAttributeUniqueID\":\"custom_cc_Escrow_Buddy_authdb_Enabled\",\"Value\":\"Installed - Auth Enabled\"},{\"Name\":\"Remove Old kGinger Agents\",\"CustomAttributeUniqueID\":\"custom_cc_remove_old_kginger_agents\",\"Value\":\"\\/bin\\/bash: line 22: \\/var\\/bluesky\\/.getHelp: No such file or directory\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nsetremotelogin: remote login is already Off.\\nStarting...\\nRemoved preference to start ARD after reboot.\\nDone.\\nmv: rename \\/etc\\/ssh\\/sshd_config.kadminbackup to \\/etc\\/ssh\\/sshd_config: No such file or directory\\n<dscl_cmd> DS Error: -14009 (eDSUnknownNodeName)\\ndelete: Invalid Path\\nmv: \\/etc\\/ssh\\/sshd_config.kadminbackup: No such file or directory\\nNo receipt for 'com.kginger.remote' found at '\\/'.\\nNo receipt for 'com.mac-msp.bluesky.update' found at '\\/'.\\nNo receipt for 'com.solarwindsmsp.bluesky' found at '\\/'.\\nNo receipt for 'com.solarwindsmsp.bluesky.admin.pkg' found at '\\/'.\\nNo receipt for 'com.solarwindsmsp.bluesky.pkg' found at '\\/'.\\nNo matching processes were found\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nWarning: Expecting a LaunchDaemons path since the command was ran as root. Got LaunchAgents instead.\\n`launchctl bootout` is a recommended alternative.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nWarning: Expecting a LaunchDaemons path since the command was ran as root. Got LaunchAgents instead.\\n`launchctl bootout` is a recommended alternative.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nWarning: Expecting a LaunchDaemons path since the command was ran as root. Got LaunchAgents instead.\\n`launchctl bootout` is a recommended alternative.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nWarning: Expecting a LaunchDaemons path since the command was ran as root. Got LaunchAgents instead.\\n`launchctl bootout` is a recommended alternative.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nWarning: Expecting a LaunchDaemons path since the command was ran as root. Got LaunchAgents instead.\\n`launchctl bootout` is a recommended alternative.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nrm: \\/etc\\/paths.d\\/munki: No such file or directory\\nNo receipt for 'com.github.munkireport' found at '\\/'.\\nNo receipt for 'com.googlecode.munki.admin' found at '\\/'.\\nNo receipt for 'com.googlecode.munki.app' found at '\\/'.\\nNo receipt for 'com.googlecode.munki.app_usage' found at '\\/'.\\nNo receipt for 'com.googlecode.munki.core' found at '\\/'.\\nNo receipt for 'com.googlecode.munki.launchd' found at '\\/'.\\nNo receipt for 'com.googlecode.munki.no-python' found at '\\/'.\\nNo receipt for 'com.googlecode.munki.python' found at '\\/'.\\nNo receipt for 'com.kginger.middleware' found at '\\/'.\\nNo receipt for 'com.kginger.munki-conditions' found at '\\/'.\\nNo receipt for 'com.kginger.munki-conditions-icloudsync' found at '\\/'.\\nNo receipt for 'com.monitoringclient.pkg.check_munkireport_link' found at '\\/'.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nNo receipt for 'com.monitoringclient.pkg.check_folder_sizes' found at '\\/'.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nNo receipt for 'com.github.munkireport' found at '\\/'.\\nNo receipt for 'com.github.munkireport-python2' found at '\\/'.\\nNo receipt for 'io.macadmins.python.recommended' found at '\\/'.\\nNo receipt for 'org.macadmins.python.recommended' found at '\\/'.\\nWarning: Expecting a LaunchDaemons path since the command was ran as root. Got LaunchAgents instead.\\n`launchctl bootout` is a recommended alternative.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nWarning: Expecting a LaunchDaemons path since the command was ran as root. Got LaunchAgents instead.\\n`launchctl bootout` is a recommended alternative.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nNo receipt for 'connectwisecontrol-9d2d93c8fbb990c7' found at '\\/'.\\nNo receipt for 'screenconnect-c000d4275c180f66' found at '\\/'.\\nNo receipt for 'screenconnect-cce341f45450602b' found at '\\/'.\\nUnload failed: 5: Input\\/output error\\nTry running `launchctl bootout` as root for richer errors.\\nNo receipt for 'com.github.grahampugh.erase-install' found at '\\/'.\\nNo receipt for 'com.DetectXScheduler' found at '\\/'.\\nNo receipt for 'com.thirdvantage.DetectXScheduler' found at '\\/'.\\n{"id":"<[email protected]>","message":"Queued. Thank you."}\\nremoved\"}]",
      "altitude": null
    },
    "hudu": [
      {
        "company_id": 36
      }
    ]
  }

Please let me know if I’ve left out some data or I can make anything more clear.

Information on your n8n setup

  • n8n version: 1.83.2
  • Database (default: SQLite): PostgresQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker on Digital Ocean
  • Operating system: Ubuntu 22.04

hello @russellkg

DateTime accepts timestamps as numbers, not as strings. That’s why it doesn’t work.

Try this one:
{{ DateTime.fromSeconds(Number($json.mosyle.date_enroll), {zone: 'utc'}).toFormat('yyyy-MM-dd HH:mm') }}

And take note, that the date_last_bit is not a timestamp.

1 Like

Thanks! That helped get the script to a functional state.

Why do you say it isn’t a timestamp? I’m assuming you mean fields like date_last_beat, which comes to me with the number of seconds in it. The field holds the date and time that the computer last checked in. It displays as a date on the website. All the date relevant fields have a Unix timestamp until I convert it to a human readable format for storing in another platform.

-Russ

in the example it was a time string:
"date_last_beat": "2025-03-19 19:10"

Ah. Thanks.

In this case, all of the date fields come from Mosyle with the number of seconds since 1/1/1970. One of the things I’m doing with them is converting the format. When I insert the date into snipe-it, it expects me to put it in yyyy-MM-dd format prior to applying it to the field. I believe I have it sorted now.

Thanks again for the help.

-Russ

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.