Connectors

Connectors

Remove milliseconds from date

Member
edited May 2024 in Connectors

I am building a connector which requires the date in the API call, however it needs to be format YYYY-MM-DDTHH:MM:SSZ.

today = new Date(); provides the date however it also includes milliseconds. How can I get the date without milliseconds or remove them after getting the date? I will then also need to remove 30 days as I need to two date to only pull in data from last month until now (or last 30 days)

thanks

Welcome!

It looks like you're new here. Members get access to exclusive content, events, rewards, and more. Sign in or register to get started.
Sign In

Answers

  • What's the language?

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • In Python…

    1. today = datetime.utcnow()
    2. today = today.replace(microsecond=0)
    3. past_date = today - timedelta(days=30)
    4. formatted_today = today.strftime('%Y-%m-%dT%H:%M:%SZ')
    5. formatted_past_date = past_date.strftime('%Y-%m-%dT%H:%M:%SZ')
    6. print("Current date in required format:", formatted_today)
    7. print("Date 30 days ago in required format:", formatted_past_date)

    In Javascript…

    1. let today = new Date();
    2. today.setMilliseconds(0);
    3. let pastDate = new Date(today);
    4. pastDate.setDate(today.getDate() - 30);
    5. function formatDate(date) {
    6. let year = date.getUTCFullYear();
    7. let month = String(date.getUTCMonth() + 1).padStart(2, '0');
    8. let day = String(date.getUTCDate()).padStart(2, '0');
    9. let hours = String(date.getUTCHours()).padStart(2, '0');
    10. let minutes = String(date.getUTCMinutes()).padStart(2, '0');
    11. let seconds = String(date.getUTCSeconds()).padStart(2, '0');
    12. return ${year}-${month}-${day}T${hours}:${minutes}:${seconds}Z;
    13. }
    14. let formattedToday = formatDate(today);
    15. let formattedPastDate = formatDate(pastDate);
    16. console.log("Current date in required format:", formattedToday);
    17. console.log("Date 30 days ago in required format:", formattedPastDate);

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • Member
    edited May 2024

    Hi, this is in DOMO, building a custom connector, so a version of JAVA.

  • Got it. I have not braved the world of custom connectors yet.

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

Welcome!

It looks like you're new here. Members get access to exclusive content, events, rewards, and more. Sign in or register to get started.
Sign In