Actually I am working with angular 4 application. I am having a scenario like, I have to send the Date for as dd/mm/yyyy to the server.
I am using property as input type ="date". But this property returns the value like yyyy/mm/dd. so how do I change the output format of the Date.
Students.html
<input type="date" [(ngModel)]="Students.dob" name="Students.dob">
After selecting the date, when I am check with console.log().
Students.components.ts
checkDate() { console.log(Students.dob); }
Finally the output was yyyy/mm/dd..
Is there any way to overcome this issue? kindly let me know.
To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.
dd/mm/yyyy.
You could change the date into dd/mm/yyyy
format using DatePipe
inside the checkDate()
function. like below. And send that date into the server side.
first import the DatePipe
into your component
import { DatePipe } from '@angular/common';
then use it like below
checkDate() {
const dateSendingToServer = new DatePipe('en-US').transform(this.Students.dob, 'dd/MM/yyyy')
console.log(dateSendingToServer);
}
working example you could be found here on STACKBLITZ DEMO.
Hope this will help to you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With