SQLite Forum

Add into date in sqlite

Add into date in sqlite

(1) By anonymous on 2021-05-11 06:16:07 [link] [source]

I have a table with following fields: TABLE dat(a int,dat date,freq int); I want get a new value in ALIAS column by adding "dat" and "freq" data. I tried in following ways: select a,dat,freq,date(dat,"+5 Year") as Due_Date from dat; which working fine result is: 2|2020-01-01|3|2025-01-01 But my object is to add freq value in dat value so i tried as follow: select a,dat,freq,date(dat,"+freq Year") as Due_Date from dat; which is not giving result and remain result as: 2|2020-01-01|3

so I need to know how possibly method to get my required result. Regards

(2.1) By Keith Medcalf (kmedcalf) on 2021-05-11 06:41:52 edited from 2.0 in reply to 1 [source]

select a, 
       date(dat, freq || ' year') as Due_Date
  from dat

The value of freq (as a string) is concatenated with the constant ' year', not part of the constant itself.