Forum Discussion

8 Replies

  • One impediment I see to people not using the API and script more is that they don't understand how to deal with date fields. When a date field is returned from the API it is not human readable - rather it is presented as an integer repenting  the number of milliseconds since the start of the Unix Epoch (midnight Jan 1, 1970). A typical date field returned by API_DoQuery might look like this:

    1435579444018


    Surprisingly, JavaScript does not have native features to convert this representation to a human readable format using patterns such as "mm/dd/yy". In the past I have used the wonderful library datejs to convert and manipulate dates:

    https://github.com/datejs/Datejs


    But it is just another library to load and in my work on the General Record Picker I wanted my interface to be screaming fast but still be able to format dates using the convenience of a library. Well it turns out that QuickBase uses the jQueryUI library on its forms and the date widget has methods to convert a date from the raw millisecond to a human readable format:

    >$.datepicker.formatDate("mm/dd/yy", new Date( parseInt("1435579444018" ,10)) );
    >"06/29/2015"

    Since this library is already loaded on QuickBase's pages you may as well use it. Here are the docs which show the wide range of human date formats you can generate:

    jQueryUI FormatDate Utility method
    https://api.jqueryui.com/datepicker/#utility-formatDate
    • JeffKelly1's avatar
      JeffKelly1
      Qrew Member
      Any tips on how to do this in Python? I've tried using the datetime module but for some reason it's not recognizing my date string, even though my dates are "mm/dd/yyyy" and I'm passing it the "%m/%d/%Y" format. I'm also using pyqb since I'm not that familiar with the QuickBase API yet.

      ------------------------------
      Jeff Jeff
      ------------------------------
      • AustinK's avatar
        AustinK
        Qrew Commander
        I'm assuming you are using something like date.strftime right now? From what I can see you need to use that function but you will need to convert the milliseconds into seconds so divide them by 1000 before trying to convert them into a date or datetime. This is the solution I have found.

        import datetime
        date
        = datetime.datetime.fromtimestamp(milliseconds/1000.0)
        date
        = date.strftime('%Y-%m-%d %H:%M:%S')


        You can also use Pandas to do this if you by any chance have it loaded.
  • Dan I'm trying to perform a calculation with a date field and the value I have stored is 5/26/2016 on the record. The API returns 1464220800000. The app setting is set to EST. I take this value and create a date with it and pass it to a function AddBusinessDays(d,n) d = date | n = # of days to add
    if you do $.datepicker.formatDate("mm/dd/yy", new Date( parseInt("1464220800000" ,10)) ); for me my console returns 5/25/16 at 8pm applying -4 hours for EST. so this date is whats being passed into the AddBusinessDays and that function does    d = new Date(d.getTime());  which returns 1464148800000. The timezone is getting applied twice. I find coding with dates really confusing for some reason. Any suggestions would be greatly appreciated!
  • I am at Google IO on a tablet so I can't type much. I would use datejs or moments (both used  by QB) - to manipulate dates.
  • When I calculate days I skip weekends but I also have an object with specific dates to exclude as well. Can I use that object with those as well?