Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How do I set the value of a date picker?

I'm using the following to set the selected value of a date picker:

picker.value = win.selectedDate;

where selectedDate is a custom property on the Window.

But this doesn't seem to work. The date picker always defaults to the system date.

Am I doing something wrong or is this a bug?

— asked April 26th 2010 by Rob Laveaux
  • datepicker
  • I'm having the same problem with any datatype.. Have you managed to find a solution? I even tried setting it from an event on another control in the same window, to avoid the "control need to be loaded before setting the selected row".

    — commented November 12th 2010 by Ole Gade Nielsen
  • selectedDate should be Date object

    — commented September 23rd 2011 by Aleksandar Glisovic

6 Answers

  • It's already 2 years and it is still not possible to dynamically change value of date picker. It is sometimes quite annoying to develop in decelerator (uh eh sry I mean appcelerator).

    — answered July 3rd 2012 by Jiri Chara
  • The Kitchen Sink demo shows how to set the default value of the picker:

    var value = new Date();
    var picker = Ti.UI.createPicker({
    — answered August 10th 2011 by Michael Stelly
    1 Comment
    • don't want default. Run time is preferable without having to recreate the object

      — commented October 14th 2011 by Dimitri Adamou
  • the solution is simple, but I had to give a look to the source code to get it. the API documentation is poor.

    this worked for me:

    var default_date = new Date(2010, 05, 05);
    var picker_date = Titanium.UI.createPicker({
      type:  Titanium.UI.PICKER_TYPE_DATE,
      value: default_date

    you have to use the object Date of javascript, you can find a description here

    pay attention to the month and the day fieds, because indexes starts from 0.

    eg: Jun 04 2010 => new Date(2010, 05, 05);

    — answered January 12th 2011 by Emanuele Gaspari Castelletti
  • I'm not sure if this helps, but I've found after initializing the picker view the only way to change the value of the picker is to have initialized a 'change' EventListener:


    After adding this listener I could update the value of the data picker with:

    mPicker.value = <<some date>>;

    — answered May 17th 2011 by Ben Talberg
  • Even faster, supposing you are working with Alloy and have a date picker with id="date_picker".

    var value = new Date("2015-06-18");
    $.date_picker.value = value;
    — answered June 18th 2015 by Nicola De Franceschi
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.