Skip to content

Instantly share code, notes, and snippets.

@kenjosling
Last active July 8, 2018 14:23
Show Gist options
  • Save kenjosling/cb30ae75cde554b0bdcfd1805bc00fba to your computer and use it in GitHub Desktop.
Save kenjosling/cb30ae75cde554b0bdcfd1805bc00fba to your computer and use it in GitHub Desktop.
function getDateFilter(dateRange) {
if(!dateRange) return "";
var chrono = require('chrono-node');
var dateFormat = require('dateformat');
var dateString = chrono.parseDate(dateRange.entity).toDateString();
var date = dateFormat(new Date(dateString), "isoUtcDateTime");
if(dateRange.entity.toLowerCase().indexOf("last") >= 0) {
return " and CreateDate gt datetime'" + date + "'";
}
if(dateRange.entity.toLowerCase().indexOf("before") >= 0) {
return " and CreateDate lt datetime'" + date + "'";
}
if(dateRange.entity.toLowerCase().indexOf("after") >= 0) {
return " and CreateDate gt datetime'" + date + "'";
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment