DatePicker

  1. 5 years ago

    Joel_Eisenstat

    16 Jul 2018 User since 2016

    Hi ,
    Just wondering on how to set the DatePicker to a specified date .
    DB data is <start date = "2018-08-05 18:05:36+00"> which was uploaded from the
    startdatePicker, a Creo Date value . However using the value directly gives the runtime error
    Runtime Error
    Unable to convert object to Date.

    Creo code to convert to Date;
    var d = Date(rs.startdate,"yyyy-MM-dd","EST");
    startdatePicker.setDateAnimated(d, true);
    However startdatePicker defaults to todays date as d goes to todays date .
    Not sure what I am missing.
    Thanks
    Joel

  2. Joel_Eisenstat

    16 Jul 2018 User since 2016

    The db date data type has to be date as opposed to timestamp with zone which is the equivalent to the date Picker format .

  3. andrea

    16 Jul 2018 Administrator User since 2016

    Hi @Joel_Eisenstat ,
    if I understand correctly, the startdate field of your DB is a string that you fill with the content of the property date (this object is a Date) of a DatePicker (startdatePicker).
    If you use a Date object in a method that expect a string as input, Creo tries to convert the Date to a string and in this case it results in a string like "2018-08-05 18:05:36 +0000".
    With this string as an input the Date(rs.startdate,"yyyy-MM-dd","EST"); returns the current date because it fails to parse the "2018-08-05 18:05:36 +0000" string with the format "yyyy-MM-dd", and when it fails it returns the current date.
    The format string must match exactly the input date string, so the string "2018-08-05 18:05:36 +0000" can be parsed by:

    var d = Date(Label2.text, "yyyy-MM-dd HH:mm:ss '+0000'", "UTC");
    startdatePicker.date = d;

    Or, if you prefers to write to the DB a different format, you can get the string value from the picker with
    DatePicker1.date.format("yyyy-MM-dd HH:mm", "PST");
    and then set this string from the DB to the picker with:

    var d = Date(Label1.text, "yyyy-MM-dd HH:mm", "PST"); 
    startdatePicker.date = d;
  4. Joel_Eisenstat

    17 Jul 2018 User since 2016

    Thanks Andrea for the thorough explanation. ,
    Another issue withe DatePicker is in obtaining the current value , in this case the time , when I format the value the result is off by an hour.
    time = timePicker.date.format ("yyyy-MM-dd HH:mm:ss", "EST");
    The time given by the Console is 2018-07-17 06:57:10 where the DatePicker is 7 57 AM .
    Regards
    Joel

  5. andrea

    17 Jul 2018 Administrator User since 2016

    @Joel_Eisenstat,
    the DatePicker shows the time relative to its time zone, so I suppose that the DatePicker in your project is configured with a different time zone from the "EST" time zone you use to get the string representation of the DatePicker's date.

  6. Joel_Eisenstat

    18 Jul 2018 User since 2016

    I will check if "daylight savings " is the issue .
    Thanks

or Sign Up to reply!