0
Javascript trasform test to date
HTML <input class="form-control" name="birthday" type="text" value="44/01/1985" placeholder="DD/MM/YYYY"> Js var y = document.querySelector('input[name=birthday]').placeholder; var x = document.querySelector('input[name=birthday]').value; hi I can't find a solution for my plugin. I can't transform var X to date I want day, mounth, year Placeholder change for country and i want risolve this
3 Answers
+ 1
Are you trying to assign, day to 44, month to 01 and year to 1985?
0
yes, but based on the format because the format changes according to the language and country of origin eg yyyy / mm / dd, dd / mm / yyyy
dd = 44
mm = 01
yyyy = 1985
0
Not sure if this is the sort of thing you need as I hardly do any html or javascript and i'm not sure how is impacts the language and country of origin...but if had a go anyway. maybe it's too simplistic for your needs...
<script>
var d = new Date();
var datestr = "17/07/1968";
var year = datestr.substr(6,4);
d.setFullYear(year);
var Month = datestr.substr(3,2);
d.setMonth(Month);
var Day = datestr.substr(0,2)
d.setMonth(Day)
document.getElementById("demo").innerHTML = d;
</script>
Have a look at the "Date" "get" methods eg getMonth()
https://www.w3schools.com/js/js_dates.asp