harveyl888 / queryBuilder

R htmlwidget for jQuery QueryBuilder filtering of data frames
12 stars 10 forks source link

Date format #6

Open harveyl888 opened 6 years ago

harveyl888 commented 6 years ago

From @cegbuna Another issue I've encountered is the inability to change the format of the date select box. I'm currently querying from SQL database via RMySQL and the date format it recognizes is '%Y-%m-%d %H:%M:%S'. When I select or pick a date in the date select box, it's in "%Y-%m-%d" and the SQL query doesn't recognize it. Is there a way to format the date select box to reflect the format RMySQL recognizes?

harveyl888 commented 6 years ago

@cegbuna I've added the ability to specify a date mask. This should return the date in a user-specified format. It currently only works with the formatting styles listed in bootstrap datepicker (this is the plugin used). Date formats are listed at https://bootstrap-datepicker.readthedocs.io/en/stable/options.html#format.

I understand that this will not solve your issue as you require a datetime format and currently I've only integrated bootstrap datepicker. I'll see if I can implement this in the near future.

In the meantime, there could be a couple of solutions. If you are looking for a specific date and time (as opposed to before or after a date), you could use a text input and simply type in the date. A second solution, if the time itself is not of importance, is to scan through the query prior to running the sql query and add 00:00:00 after each date. This could be done using regex.

t <- "mpg > 5 & Date < 2017-20-11"
gsub( '(\\d\\d\\d\\d-\\d\\d-\\d\\d)', '\\1 00:00:00', t)
# output = "mpg > 5 & Date < 2017-20-11 00:00:00"
cegbuna commented 6 years ago

Thanks for the update