Trouble arises with the date-picker component in Angular

There's a specific concept known as "campaign duration" where you can select a date between the first and last day of the month. If you choose a date outside this range, such as a date from the following month, the Backend API will respond with an "Input param error."

If I select the last date on the date selector (the 30th day of the month), the Backend API will also return an "Input param error." This indicates that it treats the 30th day as if it were the 1st day of the next month. To resolve this issue, I need to adjust my date selection by subtracting one day before sending it through the API, since the date is in string format. How can I reduce the string number by one before sending it via the API? https://i.sstatic.net/qvLj2.png

Answer №1

To decrease the date by one day, follow these steps:

Start by converting your string into a date:

const dateString = '2011-04-11T10:20:30Z';
let originalDate = new Date(dateString);

Next, subtract one day from the date:

originalDate.setDate(originalDate.getDate() - 1);

Answer №2

If you want to convert a string into a date and subtract days, check out momentjs. Here is an example:

newEndDate = moment(selectedDate, 'DD/M/YYYY').subtract(1, 'day');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking for jQuery bbq... is the grill fired up yet?

In my exploration of the jQuery bbq plugin, I noticed that there is no reference to document.hash in the code. I believe that the function for retrieving the hash is located at line 1094: function get_fragment( url ) { url = url || location.href; ...

JavaScript - Struggling with decoding a JSON object

Having some difficulty with JSON object parsing, Take a look at my code: var data = '[{"image:loc":["https://cdn.shopify.com/s/files/1/0094/2252/products/YZY-KW3027.053.jpg?v=1539344090"],"image:title":["Yeezy WMNS Tubular Boot Washed Canvas - Limes ...

Efficient approach for combining list elements

I have a collection of content blocks structured like this: interface Content{ type: string, content: string | string[] } const content: Content[] = [ { type: "heading" content: "whatever" }, { type: "para&quo ...

Developing Angular2 applications in Visual Studio Team Services (formerly known as Visual Studio Online)

Currently, I have an angular2 client integrated into a Visual Studio vNext (ASP.Net 5) project. During my attempt to create a build in Visual Studio Team Services, I encountered errors similar to this one during the build step: It appears that module &a ...

Failed AJAX Request - Google Chrome Experiences Issue

I have been working on a website that loads HTML content from a template page and then pulls in data from an XML file. This process is initiated in the document.ready function as shown below: $.ajax({ type : "GET", url : "t ...

What is the best way to implement JQuery in order to trigger an event in a text box whenever the user hits the "enter

Also, refrain from submitting the form if the user hits enter in THAT PARTICULAR input field. ...

Using AngularJS with the Phonegap Facebook plugin

I am looking to build a Javascript app and deploy it on Android and iOS using Phonegap. My goal is to integrate Facebook login into the app. After exploring the phonegap-facebook plugin, I was able to successfully implement the Facebook login feature. How ...

Issue with Bootstrap Table Style When Using window.print();

The color of my Bootstrap table style is not displaying correctly in the print preview using window.print(). Here is a screenshot showing that the table style is not working properly: https://i.stack.imgur.com/eyxjl.jpg Below is the code I am using: < ...

Using Angular to condense or manipulate an array

I am working with a JSON response that contains arrays of arrays of objects. My goal is to flatten it in an Angular way so I can display it in a Material Table. Specifically, I want to flatten the accessID and desc into a flat array like [ADPRATE, QUOCON, ...

How can this be happening? It's expected that items will be printed, but for some reason

I'm struggling to figure out why the console.logs aren't showing up. import { GenericRepository, getGenericRepository } from '../src/database/repository/GenericRepository'; import { start, stop } from '../src/index'; import r ...

What is the best way to access an object's key within an array using TypeScript?

How can I access the key values of the objects stored in a predefined array? const temp = [ { key: "name", value: "mike" }, { key: "gender", value: "male" }, ]; I am interested in retrieving the key values, such as name and gender, from the objects wi ...

Type definition for Vuex store functionality

Working on creating a versatile type to provide typing hints for mutations in Vuex. After reading an inspiring article on Vuex + TypeScript, I decided to develop something more generic. Here is what I came up with: export type MutationType<S, P, K exten ...

Exploring Angular 2 Routing with onActivate Functionality

I'm having some trouble setting up a component to use the routerOnActivate hook. I keep encountering an error message stating that the property 'routerOnActivate' is missing in the component called 'SettingsHomeComponent', with the ...

Guide on catching network errors using Axios request interceptor?

After encountering issues with our Vue application, I observed in the Sentry logs that the problem may stem from an unreliable network: Error: Network Error Error: Request aborted I wanted to display a warning message to the user but couldn't find a ...

Personalized JQuery popup before leaving the page

Looking to display a unique jQuery dialog box with options for Yes, No, and Cancel when a user attempts to navigate away from the current page or close the window. The default browser dialog confirmation is displayed on the beforeload event, but we are tr ...

THREE.js - Transformative Vertex Shader for Billboards

I am trying to figure out how to make an instance of THREE.Mesh always face the camera using a vertex shader instead of just relying on the [THREE.Mesh].lookAt() method. After reading through NeHe's Billboarding tutorial, I understand the concept exc ...

Creating a Future Prediction Graph with ECharts

I am looking to create a forecast chart that includes both Actual values (presented as a line chart) and projected values (displayed as a dotted chart). An example of what I have in mind can be seen here, created using Excel: https://i.sstatic.net/q18An.pn ...

Utilizing the namespace importation method correctly

How can I efficiently utilize classes from a namespace that may be the same or different from the current file's namespace? I currently have the following two files. TypeA.ts: export namespace Game { @ccclass export class TypeA extends cc.Component ...

effective ways to extract objects from nested structures using a specific identifier

In this sample data, I am looking to filter an object based on its ID key let myData = { "nodeInfo": { "9": { "1": { "ID": "14835" ...

Adjust the position of vertices when the mouse hovers over them

I have a PlaneGeometry and I am trying to adjust the z position of the vertex being hovered over, but I am uncertain about how to retrieve it. //THREE.WebGLRenderer 69 // Creating plane var geometryPlane = new THREE.PlaneGeometry( 100, 100, 20, 10 ); ...