I want to compare a init time with current time and results are weird.
From a String a build a date like shown:
fechIni = "2019-02-07"
timeIni = "17:40"
var datepartsIni = fechIni.split("-");
var horapartsIni = timeIni.split(":");
var dateIni = new Date(datepartsIni[0], datepartsIni[1], datepartsIni[2], horapartsIni[0], horapartsIni[1]);
if print dateIni, I got something like: Thu Mar 07 2019 17:40:00 GMT-0300 (hora de verano de Chile) Witch I think is right.
Then, I compare that date with current date (for not allowing doing something).
var currentdate = new Date();
When I compared them, (imagine dateIni is earlier than currentdate) with something like this:
if (dateIni > currentdate) {... do stuff ...}
I got true when it should be false. I have try with .valueOf(), convert to milis, convert to epoch and calculating difference... but I can't do the trick.
I attach a screenshot of console output and code.
UPDATE: Solved!! The trick was setting the date:
var dateFin = new Date(datepartsFin[0], datepartsFin[1] - 1, datepartsFin[2], horapartsFin[0], horapartsFin[1]);
Instead of
var dateFin = new Date(datepartsFin[0], datepartsFin[1], datepartsFin[2], horapartsFin[0], horapartsFin[1]); //WRONG in my case