Input Date Format With Dd/Mm/Yyyy in the Input Field

Is there any way to change input type="date" format?

It is impossible to change the format

We have to differentiate between the over the wire format and the browser's presentation format.

Wire format

The HTML5 date input specification refers to the RFC 3339 specification, which specifies a full-date format equal to: yyyy-mm-dd. See section 5.6 of the RFC 3339 specification for more details.

This format is used by the value HTML attribute and DOM property and is the one used when doing an ordinary form submission.

Presentation format

Browsers are unrestricted in how they present a date input. At the time of writing Chrome, Edge, Firefox, and Opera have date support. They all display a date picker and format the text in the input field.

Desktop devices

For Chrome, Firefox, and Opera, the formatting of the input field's text is based on the browser's language setting. For Edge, it is based on the Windows language setting. Sadly, all web browsers ignore the date formatting configured in the operating system. To me this is very strange behaviour, and something to consider when using this input type. For example, Dutch users that have their operating system or browser language set to en-us will be shown 01/30/2019 instead of the format they are accustomed to: 30-01-2019.

Internet Explorer 9, 10, and 11 display a text input field with the wire format.

Mobile devices

Specifically for Chrome on Android, the formatting is based on the Android display language. I suspect that the same is true for other browsers, though I've not been able to verify this.

How to change date format to dd/mm/yyyy in html input

There is no way to change the default date type input except using CSS and js

$("input").on("change", function() {
this.setAttribute(
"data-date",
moment(this.value, "YYYY-MM-DD")
.format( this.getAttribute("data-date-format") )
)
}).trigger("change")
input {
position: relative;
width: 150px; height: 20px;
color: white;
}

input:before {
position: absolute;
top: 3px; left: 3px;
content: attr(data-date);
display: inline-block;
color: black;
}

input::-webkit-datetime-edit, input::-webkit-inner-spin-button, input::-webkit-clear-button {
display: none;
}

input::-webkit-calendar-picker-indicator {
position: absolute;
top: 3px;
right: 0;
color: black;
opacity: 1;
}
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
<input type="date" data-date="" data-date-format="DD/MM/YYYY" value="2020-08-29">

Date input field DD/MM/YYYY with input type text

Use HTML5 date input:

<input type="date" /> 

Changing input date data-type to DD/MM/YYYY instead of MM/DD/YYYY with require

Instead of this use jquery's Datepicker.IN Jquery's Datepicker You can set any date Format You want.

Add this code in script tags at the end of body

<script>$('#date').datepicker({ dateFormat: 'dd-mm-yy' }).val();</script>

Just Add These Cdn's in head section in your code

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

How to change date input type to DD/MM/YYYY in Angular?

If you are using ngx-bootstrap... I think you are from the bsDatepicker directive on your input. You can use the bsConfig directive to format the date input. https://valor-software.com/ngx-bootstrap/#/datepicker#format

<div class="form-group">
<label>{{"StartDate" | localize}}*</label>
<input required class="form-control m-input" type="text" bsDatepicker
datePickerMomentModifier [(date)]="ticketWorkDetail.workDetailStartDate"
[bsConfig]="{ dateInputFormat: 'DD/MM/YYYY' }"
id="TicketWorkDetail_WorkDetailStartDate"
name="TicketWorkDetail_WorkDetailStartDate">
</div>

You can set the input type attribute to text and the bsDatepicker directive will do it's work.



Related Topics



Leave a reply



Submit