0

after resolving my problem about converting a string into a date in titanium , i managed to get that date in milliseconds and the current time too as shown in this code :

    Ti.API.error("+*///+++ FormatDate(NightsArray[i][3]).getTime() : "+parseInt(FormatDate(NightsArray[i][3]).getTime()));
    var date1 = parseInt(FormatDate(NightsArray[i][3]).getTime());

    Ti.API.error("+*///+++ d.getTime() : "+parseInt(d.getTime()));
    var date2 = parseInt(d.getTime());

    Ti.API.error("+*///+++ comparaison : "+date2 < date1);
    Ti.API.error("+*///+++ comparaison : "+date2 > date1);

    if(date2 > date1)
        Ti.API.error("+*///+++ Diff : "+date2 - date1);
    else    
        Ti.API.error("+*///+++ Diff : "+date1 - date2);

i parsed these both dates formatted in milliseconds into integers hopping finally to get rid of dates problems by only working with numbers but as shown in the console : all comparaisons return 0 and the difference NaN

[ERROR] :  +*///+++FormatDate(date) : Thu Feb 20 2014 23:00:00 GMT+0100 (CET)
[ERROR] :  +*///+++ FormatDate(NightsArray[i][3]).getTime() : 1392933600000
[ERROR] :  +*///+++ d.getTime() : 1392634864589
[ERROR] :  0
[ERROR] :  0
[ERROR] :  NaN 

What's wrong !

Community
  • 1
  • 1
Bardelman
  • 2,176
  • 7
  • 43
  • 70

1 Answers1

1

There is a simple mistake in your code. Your code will not work unless you put the expressions in parentheses.

Try changing the code as follows

Ti.API.info("comparisson-1 : " + (date2 < date1));
Ti.API.error("comparisson-2 : " + (date2 > date1));

if(date2 > date1)
    Ti.API.info("Difference-1 " + (date2 - date1));
else    
    Ti.API.error("Difference-2 " + (date1 - date2));

Check the above code and let me know the progress

Anand
  • 5,323
  • 5
  • 44
  • 58