Convert DD-MM-YYYY to YYYY-MM-DD format using Javascript
This should do the magic
var date = "03-11-2014";
var newdate = date.split("-").reverse().join("-");
Javascript function to convert date yyyy/mm/dd to dd/mm/yy
If you're sure that the date that comes from the server is valid, a simple RegExp can help you to change the format:
function formatDate (input) {
var datePart = input.match(/\d+/g),
year = datePart[0].substring(2), // get only two digits
month = datePart[1], day = datePart[2];
return day+'/'+month+'/'+year;
}
formatDate ('2010/01/18'); // "18/01/10"
convert date from dd/mm/yyyy to yyyy-mm-dd in javascript
Do a simple split and join
var date = "03/05/2013";
var newdate = date.split("/").reverse().join("-");
"2013-05-03"
How to convert dd/mm/yyyy string into JavaScript Date object?
MM/DD/YYYY format
If you have the MM/DD/YYYY
format which is default for JavaScript, you can simply pass your string to Date(string)
constructor. It will parse it for you.
var dateString = "10/23/2015"; // Oct 23
var dateObject = new Date(dateString);
document.body.innerHTML = dateObject.toString();
Javascript convert date format from "dd/mm/yy" to "mm/dd/yyyy"
You can split the value by a /
to get the month, date and year.
var s = $('#date1').val().split('/')
$('#date2').val(`${s[1]}/${s[0]}/20${s[2]}`)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="date1" type="text" value="25/12/21" >
<input id="date2" type="text" value="12/25/2021" >
javascript format date from DDMMYYYY to DD/MM/YYYY
If that's the exact format you're looking at, then you could just parse it out:
http://jsfiddle.net/q3yrtu0z/
$('#input1').change(function() {
$(this).val($(this).val().replace(/^(\d{2})(\d{2})(\d{4})$/, '$1/$2/$3'));
});
This is designed such that if the value is exactly 8 digits, then it will format it XX/XX/XXXX.
You may want to do additional validation on the validity of the date format (although you'd have to do this for MM/DD/YYYY inputs as well anyway)
Related Topics
Javascript Json Parsing Error: Unexpected Token ' in Json At Position 1
Starting the Week on Monday With Isoweekday()
Javascript Function (Input Date Bigger Than Today Date)
How to Load a Font File in Vuejs and Webpack
How to Detect If a Browser Is Blocking a Popup
Error: Permission Denied to Access Property "Document"
How to Pass Value into Href Link of a Bootstrap Modal
How to Use Fetch Within a For-Loop, Wait for Results and Then Console.Log It
React Open Modal Window on Click in Another Component
How to Send One Alert from My Node.Js to My JavaScript Client
How Does Group by Works in Sequelize
Reinitialize Slick Js After Successful Ajax Call
Extract Part of Url With Regex
Electron - How to Add External Files
Converting Async/Await Function to Normal Es5 Targetting Ie 11