+ 1
Help in Date on JavaScript ?
hello, function myFunction() { var x = document.getElementById("myDate").value; var today = new Date(); var dd = today.getDate(); var mm = today.getMonth()+1; //January is 0! var yyyy = today.getFullYear(); document.getElementById("demo").innerHTML = x; } I want to use the date entered and put it in the new date
5 Answers
+ 10
use
var today = new Date(x);
if (today == 'Invalid Date') {
.....
// handle wrong input
.....
} else {
....
// do your thing
.....
}
+ 8
@S Vengat depends how strict you want to be. As usual JS would try to be nice and evaluate anything you pass:
-1.4.17 => Jan 04 2017
41.4.17 => Apr 17 2041,
but
41.4.41 => Invalid Date,
So like with anything else JS will do it's best to make sense of the input, but one has to be careful with that 😃😃😃
+ 5
Don't you also need to note that they have their limits?
Like 01<=dd<=31?
+ 4
Oh okay! So that's why timers can set 99:99:99 and the timer will still run!
- 1
znjsnbsb@&#-~-~÷~(@&@-*~*|×@×|+₹^~&!×+#&#*@*@-#+|*[♀√¡¡8 il il sisiwjsh8wkakkazhjskghhsiwjsgsh