Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Javascript date2str - weird behavior

  1. #1
    pstoellberger Guest

    Default Javascript date2str - weird behavior

    In my JavaScript I want to get the previous month as 2-char-string:

    Code:
    datum = new Date();
    var date_ = dateAdd(datum,-1,"m");
    get date - 1 Month

    Code:
    var month2_=date2str(date_,"MM");
    this doesn't work, shows me current month not month - 1

    Code:
    var month_="";
    if (month(date_) < 10) {
        month_ = "0" + month(date_);
    }
    else
        month_ = "" + month(date_);
    the above is a workaround that works, but its ugly

    is this a bug or am i doing something wrong?

  2. #2
    pstoellberger Guest

    Default

    I solved my problem now with GregorianCalendar, because dateadd -1 m resulted in 0 for january

    this solution is still pretty ugly, but at least its working

    Code:
    var locale = new java.util.Locale(
    "de","AT"
    );
    var calendar = new java.util.GregorianCalendar(locale);
    calendar.setTime(new Date());
    calendar.add(java.util.Calendar.MONTH,-3);
    var month2_=calendar.get(java.util.Calendar.MONTH)+1;
    if (month2_ < 10) {
        month2_ = "0" + month2_;
    }
    else
        month2_ = "" + month2_;
    var year_=calendar.get(java.util.Calendar.YEAR);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.