You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Date format of NOW() is different from DATE() #673
I've found that both GETDATE() and NOW() produce the following result:
NOW(): "2016.05.04 18:20:09.722"
However, when I'm using DATE([somedate]), I'm getting something like this:
DATE([somedate]): Wed May 04 2016 18:26:16 GMT+0200 (CEST)
The problem is that I want to count the days between today and a future date, and for DATEDIFF to function the dates need to be in the same format.
At first, I thought I can just use DATE(NOW()). In Chrome that works, and gives me a result like the above, but in Firefox, Internet Explorer, and Safari it throws an error:
DATE(NOW()): Invalid Date
Of course, I can solve this issue by using Date() or to make sure the formats match exactly: DATE(Date()) (both seem to work). So in the end, my code looks something like this:
So the data in my database is stored in a YYYY-MM-DD format, which I convert to Javascript dates using new Date() and then feed it back into alasql's DATE().
However, the solution DATE(Date()) seems a bit unnecessary, so I was wondering if the outputs could be more consistent.
In the above jsfiddle I also included a demonstration of DATE(NOW()) failing. Please use a browser other than Chrome.
Activity
mathiasrw commentedon May 4, 2016
If we get date(now) to work - would that solve it?
I have to look into what other databasese gives as result for
nowanddatetmrk commentedon May 4, 2016
I guess, although that might be a browser thing, because Chrome seems to be able to parse it properly already now.
mathiasrw commentedon May 4, 2016
Could you provide example of your data for me to see if there is a better solution for you?
mathiasrw commentedon May 4, 2016
Hmm. What do you get if you print
alasql.version?I cant replicate.
I get this from 0.2.5-develop-1262
tmrk commentedon May 4, 2016
Well, as I wrote I am using
DATE(Date())to get today's date in the right format, so my code looks something like this: https://jsfiddle.net/fgwtu8e1/4/ (NB: I simplified it a lot to make it easier to read.)So the data in my database is stored in a YYYY-MM-DD format, which I convert to Javascript dates using
new Date()and then feed it back into alasql'sDATE().However, the solution
DATE(Date())seems a bit unnecessary, so I was wondering if the outputs could be more consistent.In the above jsfiddle I also included a demonstration of
DATE(NOW())failing. Please use a browser other than Chrome.ps. I'm using 0.2.6
mathiasrw commentedon May 4, 2016
Woops...
I have a feeling the good solution would be to let
DATE()return today if nothing is set.tmrk commentedon May 5, 2016
I don't see any problem with that as long as it will work with
DATEDIFFproperly.Although it's not really standard: http://www.w3schools.com/sql/sql_dates.asp - is it? I'm not an SQL expert, so it's up to you guys. ;)
Thanks for dealing with the issue!
mathiasrw commentedon May 7, 2016
Realy good link. I will look into verifying we get them all implemented...