Remove milliseconds from date

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
Answers
-
What's the language?
** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **0 -
In Python…
- today = datetime.utcnow()
- today = today.replace(microsecond=0)
- past_date = today - timedelta(days=30)
- formatted_today = today.strftime('%Y-%m-%dT%H:%M:%SZ')
- formatted_past_date = past_date.strftime('%Y-%m-%dT%H:%M:%SZ')
- print("Current date in required format:", formatted_today)
- print("Date 30 days ago in required format:", formatted_past_date)
In Javascript…
- let today = new Date();
- today.setMilliseconds(0);
- let pastDate = new Date(today);
- pastDate.setDate(today.getDate() - 30);
- function formatDate(date) {
- let year = date.getUTCFullYear();
- let month = String(date.getUTCMonth() + 1).padStart(2, '0');
- let day = String(date.getUTCDate()).padStart(2, '0');
- let hours = String(date.getUTCHours()).padStart(2, '0');
- let minutes = String(date.getUTCMinutes()).padStart(2, '0');
- let seconds = String(date.getUTCSeconds()).padStart(2, '0');
- return ${year}-${month}-${day}T${hours}:${minutes}:${seconds}Z;
- }
- let formattedToday = formatDate(today);
- let formattedPastDate = formatDate(pastDate);
- console.log("Current date in required format:", formattedToday);
- 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! **0 -
Hi, this is in DOMO, building a custom connector, so a version of JAVA.
1 -
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! **0
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 311 Workbench
- 7 Cloud Amplifier
- 9 Federated
- 3K Transform
- 114 SQL DataFlows
- 654 Datasets
- 2.2K Magic ETL
- 4.1K Visualize
- 2.5K Charting
- 803 Beast Mode
- 79 App Studio
- 44 Variables
- 759 Automate
- 189 Apps
- 480 APIs & Domo Developer
- 73 Workflows
- 17 DomoAI
- 40 Predict
- 17 Jupyter Workspaces
- 23 R & Python Tiles
- 408 Distribute
- 119 Domo Everywhere
- 279 Scheduled Reports
- 10 Software Integrations
- 141 Manage
- 137 Governance & Security
- 8 Domo Community Gallery
- 47 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 114 Community Announcements
- 4.8K Archive