Skip to content

Commit

Permalink
#1936 Add date function to get current date without time component
Browse files Browse the repository at this point in the history
- Add CURDATE method to AlaSQL
- Add test
  • Loading branch information
paulrutter committed Jun 18, 2024
1 parent 99c7663 commit 7ae7564
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/61date.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ stdfn.NOW = function () {
stdfn.GETDATE = stdfn.NOW;
stdfn.CURRENT_TIMESTAMP = stdfn.NOW;

/**
* Returns the current date, without time component.
* @returns date object without time component
*/
alasql.stdfn.CURDATE = function () {
var date = new Date();
date.setHours(0, 0, 0, 0);
return date;
};

// stdfn.GETDATE = function(){
// var d = new Date();
// var s = d.getFullYear()+"."+("0"+(d.getMonth()+1)).substr(-2)+"."+("0"+d.getDate()).substr(-2);
Expand Down
13 changes: 13 additions & 0 deletions test/test1936.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}

describe('Test 1936 - Check CURDATE', function () {
it('CURDATE in SELECT', function () {
let result = alasql("SELECT CURDATE()");

assert.equal(true, result[0]["CURDATE()"] instanceof Date);
assert.equal(true, result[0]["CURDATE()"].toISOString().includes("00:00"));
});
});

0 comments on commit 7ae7564

Please sign in to comment.