Date differens

You must Login before you can answer or comment on any questions.

Hello. I need to get the differens between two when choosing from a picker. This is my code:

var pickValue = 0;
picker.addEventListener('change',function(e)
{    
 
     pickValue = new Date(e.value);  
 
     pickValueMonth = pickValue.getMonth()+1;
 
     pickValue = pickValue.getHours()+":"+pickValue.getMinutes()+" - "+pickValue.getDate()+" "+monthNames[pickValueMonth];
 
});
An example for this would be something like this:
var dateDifferens = (((pickValue.getTime()-xxxValue.getTime())/1000)/3600)/24;
But because im using a picker i only have one variable ... PLS help! :) I have already looked in date.js ...

— asked 1 year ago by Nico Kjeldsen
2 Comments
  • What prevents you from using two pickers? If you want difference between now and chosen Value, you can use new Date() for now.

    — commented 1 year ago by Alexander Bauer

  • Why would i use two pickers? I mean, how would that work?? Never seen anyone use more than one picker.

    — commented 1 year ago by Nico Kjeldsen

2 Answers

To get picker work on both platforms, do this:

picker.addEventListener('change', function(e) {
    this.value = e.value;
});
 
picker.getValue = function() {
    return this.value;
};

To get date difference (and "picker.getValue" will return "Date" instance), use minus operator:

var dateDiff = picker2.getValue() - picker1.getValue();

— answered 1 year ago by Ivan Škugor
answer permalink
4 Comments
  • But how can I use Picker1 & Picker2 if I only have one picker?? Im new to programing titanium ... :-(

    — commented 1 year ago by Nico Kjeldsen

  • Using only one picker has a bug that the value of the picker is changed while changing the date, but the new value does not reflect on the UI.....

    I suggest you to use two pickers instead

    — commented 1 year ago by Jiale He

  • Create two pickers if you need two of them.

    — commented 1 year ago by Ivan Škugor

  • Show 1 more comment

Someone? Maybe little help with some code? I'm really stuck here ...

Your Answer

Think you can help? Login to answer this question!