0

I am asking for an input of type "date" and then I want to use the received dates stored in variables. I am receiving the user input correctly but the I don't know what type of data to use with JavaSript, currently I'm receiving it as "number" but it's not appropriate.

    <form #datesForm = "ngForm" (ngSubmit)="checkDates(datesForm.value)">
    <div class="elem-group inlined">
      <label>First Day Of Your Plan</label>
      <input type="date" name="firstDate" required>
    </div>
    <div class="elem-group inlined">
      <label>Last Day Of Your Plan</label>
      <input type="date" name="lastDate" required>
    </div>
    <button class="btn-fetch" (click)="checkDates(datesForm.value)">Confirm Dates</button>
    <div class="elem-group">
      <label>Select A Plan Number </label>
      <select name="planId" required>
          <option value="">Choose a number from the List</option>
          <option value="planId">Connecting</option>
      </select>
    </div>
    <button type="submit">Save the Plan</button>
</form>

export class PlansComponent {
  @ViewChild('plansForm') form: NgForm;


  checkDates(planDates: { firstDate: number, lastDate: number }) {

    if (planDates.lastDate - planDates.firstDate <= 7)

      confirm("Dates are OK");

    else

      alert("Only weekly dates");

  }

What would you have me use instead of number in my checkDates() method?

worker24_7
  • 27
  • 8
  • The format you retrieve is always of the format `yyyy-mm-dd`, so what else other than a string could it possibly be. – CBroe Jan 20 '23 at 12:27
  • So get it in string format and then break it down to the be able to do a math operation? – worker24_7 Jan 20 '23 at 12:32
  • 1
    I can't help you with the Angular aspect of this, but the `HTMLInputElement` provides the date as a `Date` instance via its `valueAsDate` property. Its `value` property is a string. Details: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#instance_properties – T.J. Crowder Jan 20 '23 at 12:38

0 Answers0