Alasql: Get Min & Max date from table?

Created on 23 Sep 2015  路  6Comments  路  Source: agershun/alasql

Hello,

Is it possible to get the Min or Max date from a table?

alasql("CREATE TABLE TestDates (StartDate DATE, EndDate DATE) ");
alasql("INSERT INTO TestDates VALUES('2015.10.23', '2015.11.24') ");
alasql("INSERT INTO TestDates VALUES('2015.11.23', '2015.12.24') ");
alasql("INSERT INTO TestDates VALUES('2015.12.23', '2015.13.24') ");

alasql("Select MIN(StartDate) FROM TestDates ");
alasql("Select MAX(StartDate) FROM TestDates ");

It returns undifined

The only way I managed to do it is to use a timestamp.

Thank

Thierry

! Feature request Good first issue Help wanted

Most helpful comment

It was fixed in January this year according to release notes, so I guess it is no longer an issue.

All 6 comments

As I recall the min and max only works on numbers.

Its a good point supporting dates.

While we do that you can check out if you can use something like

select startdate from testdates order by startdate DESC limit 1
select startdate from testdates order by startdate ASC limit 1

Thank Mathias,

That's a good trick for now.

Best regards

Thierry

Any plans to fix this ? Work arounds are ok, but it'd be nice to support MIN/MAX for date types as well.

Anyone are free to look into this. I have a feeling its not a hard fix.

Is this still an issue? The below is successfully passing the tests:

var res = [];
res.push(alasql('create table one (dateField DATE)'));
res.push(alasql('insert into one values (\'2015.10.23\'), (\'2015.11.23\'), (\'2015.12.23\')'));
res.push(alasql('select MIN(dateField) min_d from one'));
res.push(alasql('select MAX(dateField) max_d from one'));
assert.deepEqual(res, [1, 3, [{min_d: '2015.10.23'}], [{max_d: '2015.12.23'}]]);

It was fixed in January this year according to release notes, so I guess it is no longer an issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AmyBlankenship picture AmyBlankenship  路  6Comments

daffodilistic picture daffodilistic  路  3Comments

Serge-SDL picture Serge-SDL  路  4Comments

cscan picture cscan  路  4Comments

mathiasrw picture mathiasrw  路  5Comments