Hello,
I am using the EJ2 Angular Syncfusion datetime picker and I'm facing an issue with it. I need the datetime picker to show the current datetime directly in the field, but it's not working as expected. I have tried using the following code, but it's not working:
Here another issue is that when I click on today button it should take minDate Date-Time but here
its take current Date but time is not current its take starting time of the day like 12 AM;
You can use “minDate as new Date()” for your requirement. The new Date() will give the current Date and Time.
<ejs-datetimepicker [min]="minDate" format="dd/MM/yyyy h:mm a" [value]="minDate" id="ProjectSalesToOpsHand_ScheMeetWiOpeDate" name="ProjectSalesToOpsHand_ScheMeetWiOpeDate" ></ejs-datetimepicker> export class AppComponent { public minDate: Object = new Date(); } |
Sample: https://stackblitz.com/edit/angular-zbxrn6?file=src%2Fapp.component.html,src%2Fapp.component.ts
can you solve this issue also when I click on the Today button from the calendar it is directly picking the time is the day stating 12 AM? it should take current time only when I directly click on the today button.
You can bind a click event to the Today button and in the click event you can update the DatePicker component's value to the current date and time using instances. Please refer to the code snippet and sample below for more information.
[app.component.html]
<ejs-datetimepicker #sample [min]="minDate" format="dd/MM/yyyy h:mm a" [value]="minDate" id="ProjectSalesToOpsHand_ScheMeetWiOpeDate" name="ProjectSalesToOpsHand_ScheMeetWiOpeDate" (open)="onOpen(sample)" ></ejs-datetimepicker> |
[app.component.ts]
export class AppComponent { public minDate: Object = new Date();
onOpen(e) { setTimeout(function () { document .getElementsByClassName('e-btn e-today')[0] .addEventListener('click', function () { e.value = new Date(); }); }, 50); } } |