Forum Discussion
_anomDiebolt_
10 years agoQrew Elite
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
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
6 years agoQrew 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
------------------------------
------------------------------
Jeff Jeff
------------------------------
- AustinK6 years agoQrew CommanderI'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.- JeffKelly16 years agoQrew MemberThanks! I was able to convert the other way since I'm comparing dates from 2 different sources.
datetime.utcfromtimestamp(float(str(my_date)[:10])).strftime('%m/%d/%Y')
Am I missing something? Since I don't need the time of day I am getting matching dates, but this might not work if I needed the time of day.
------------------------------
Jeff Jeff
------------------------------