1
votes

I create a table as bellow,

timestamp=[2019.06.01T09:00:00.000 ,2019.06.02T09:00:00.000,2019.06.20T09:00:00.000]
sym = `MS`MS`MS$symbol;                 
price= 49.6 29.46 29.52 ;           
qty = 2200 1900 2100 ;              
t1 = table(timestamp, sym, qty, price)

Then I execute the the following code in DolphinDB Gui, select * from t1 The record set is showed like this. But I execite the following code,

days=1000*60*60*24
select * from t1 where timestamp > now()-days*30

The record set is null as showed like this.

How to select the last n days data from the dolphindb table ?

1

1 Answers

2
votes

Your code has minor data overflow issue. days is an integer (4 bytes) and the result of days * 30 exceeds integer's max value. Two ways to fix:

Method 1: convert constant 30 to 30l

days=1000*60*60*24
select * from t1 where timestamp > now()-days*30l

Method 2: use temporalAdd function

select * from t1 where timestamp > temporalAdd(now(), -30, 'd')