1

I am trying to set min and max value to angular code here is my code

 <input type="date" 
        class="form-control" 
        style="width: 30%" 
        [disabled]="!dateSent" 
        min="{{dateSent|date:'yyyy-MM-dd'}}" 
        max="{{todaysdate|date:'yyyy-MM-dd'}}" 
        #myDate
        [value]="dateReceived | date:'yyyy-MM-dd'" 
        (input)="dateReceived=$event.target.value" />

and the value of datesent and todaydate is same

dateSent=1527445800000 and todaysdate=1527445800000 can any one help me and the out put is like this

enter image description here

thank you for your time and consideration

7
  • what are those two inputs?, didnt understand your question. can u please elaborate?
    – Sravan
    May 28, 2018 at 12:00
  • which inputs can you please specify names? May 28, 2018 at 12:11
  • Date sent and date recieved are two inputs, what error u r facing currrently
    – Sravan
    May 28, 2018 at 12:12
  • I set a screenshot of date received please see it's shows me dd/05/2018 instead of dd/mm/yyyy and if i remove either min or max its work good May 28, 2018 at 12:13
  • 2
    are you satisfied with my answer. May 29, 2018 at 8:52

1 Answer 1

6

You have to take new Date(dateReceived)

Component:

import { Component,OnInit} from '@angular/core';
import { FormGroup, FormBuilder } from '@angular/forms';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {

  dateSent;
  dateReceived;
  todaysdate;

  ngOnInit(){
    this.dateSent="1527445800000"
    this.todaysdate="1527445800000"

  }

}

HTML:

  <input type="date" 
    class="form-control" 
    style="width: 30%" 
    [disabled]="!dateSent" 
    min="{{dateSent|date:'yyyy-MM-dd'}}" 
    max="{{todaysdate|date:'yyyy-MM-dd'}}" 
    #myDate
    [value]="dateReceived | date:'yyyy-MM-dd'" 
    (input)="dateReceived=$event.target.value" />

Here is a Working DEMO

12
  • 1
    yes you can make it dynamic, just add new Date(dynamicValue)
    – Sravan
    May 28, 2018 at 12:32
  • 1
    even if we add new Date(milliseconds), the date value wont cahnge
    – Sravan
    May 28, 2018 at 12:33
  • 1
    @bhaumikshah, stackblitz.com/edit/…, please check now
    – Sravan
    May 28, 2018 at 12:59
  • 1
    yes because we are converting that time to UTC time when toJson is applied to it
    – Sravan
    May 28, 2018 at 13:22
  • 1
    please check now it is done
    – Sravan
    May 28, 2018 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.