[.html]
<div class="content-container-fluid">
<div class="row">
<div class="cols-sample-area" style="height:400px; margin:0 auto;">
Datepicker
<input ej-datepicker dateFormat="dd/MM/yyyy" locale="en-GB"[(ngModel)]="startDate" id="startDate" >
<input type="submit" ej-button (click)="onclick($event)" />
</div>
</div>
</div> |
[.ts]
onclick() {
var datevalue = $("#startDate").val(); //get the value of the datepicker element.
var dateobject = ej.parseDate(datevalue,"dd/MM/yyyy","en-GB");// converting the value to Dateobject of specific format and culture.
alert("ISO value:"+dateobject .toISOString());// Value converted to ISO format will be available in alert textbox.
}
|
Hi Prem,
I am using Angular2 and TypesScript.
I have come up with this which seems to work well...
< input #startDate ej-datepicker dateFormat="dd/MM/yyyy" locale="en-GB" >
@ViewChild('startDate') startDate: any;
let startDate = new Date(this.startDate.widget._preValue);
Is this OK?
Thank you. Is there a more suitable variable I could use that would provide the selected date in ISO format - from TypeScript?
ngAfterViewInit() {
this.modeldate = this.startDate.widget.model.value;
}
|
[html]
<input #datepic ej-datepicker dateFormat="dd/MM/yyyy" locale="en-GB" [(value)]="value" (ejchange)="onChange($event)" id="datepicker" > |
[ts]
export class DatepickerComponent {
value: any;
modeldate:any;
@ViewChild("datepic") startDate: any;
constructor() {
this.value =new Date();
}
onChange(args) {
var dateobject = ej.parseDate(args.value, "dd/MM/yyyy", "en-GB");// converting the value to Dateobject of specific format and culture
this.modeldate = new Date(dateobject .toISOString());// Value converted to ISO format.
alert("ISO value:"+this.modeldate);
}
ngAfterViewInit() {
this.modeldate = this.startDate.widget.model.value;
}
} |
Many thanks Prem, this resolves the issue. Again great tech support!
Hoping this thread is of help to other developers.
Regards
Mark
How do I work with DatePicker with ISO format model but display the date in "dd/MM/yyyy" format?
To handle a DatePicker with an ISO format model while displaying the date in "dd/MM/yyyy" format, you can use the format prop in Material-UI's DatePicker. Set the format attribute to "dd/MM/yyyy" to control the displayed date format. Simultaneously, ensure that the value attribute passed to the DatePicker is in ISO format. This way, you maintain ISO compatibility for handling and storing dates while presenting them in the desired "dd/MM/yyyy" format for a user-friendly display. Adjust the onChange handler accordingly to manage conversions between ISO and display formats if needed.
To know more, read here:
https://purecode.ai/blogs/mui-select/