Topic: add N years to a date field

Hi,
How can I add 65 years to a date field in a SQLExecute ?? I've tried adddate but retuns "No such function". Any idea please?
Thanks in advance!
Javi

2 (edited by mathmathou 2016-07-07 20:01:20)

Re: add N years to a date field

Hello meideprac-x,


There is no adddate function in Sqlite, this is SQL or Mysql.


What you should do is :


date(date to modify,modifier)
OR
datetime(date to modify,modifier)


In one of my database this looks like this :

SELECT
     datetime(asset.date_added) AS 'Original Date',
     datetime(asset.date_added,'+65 year') AS 'Modified Date'
FROM
     asset
WHERE
     asset.id = 13

And the result is :

2016-06-25 11:10:45
2081-06-25 11:10:45

Cheers


Mathias


PS : the datetime function also gets ride of the trailing three 0 after hour/minutes/second and is good to use for formatting dates, that's why I added it to the first unmodified element of the query

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: add N years to a date field

mathmathou wrote:
SELECT
     datetime(asset.date_added) AS 'Original Date',
     datetime(asset.date_added,'+65 year') AS 'Modified Date'
FROM
     asset
WHERE
     asset.id = 13

Thanks Mathias, that works fine!! big_smile

4 (edited by sahems.y.3 2016-08-08 19:38:51)

Re: add N years to a date field

Hello,
i am Beginner, and dont have a long  experience with  databases :§


i have a small Problem .
im My CALO Table there are 4 Fields for *Description, Period, Caldate, Duedate) and the Duedate should be= Caldate +Period , and the database has to do that automatically , i made a Button with SQL query to do that and it works good but when i search for my calculated Duedate i cant find  it   .
this is the  SQL query

UPDATE CALO
SET  Duedate = DATE(Caldate,'+365 Day')
where Period =365;


Thanks in advance for the help

Re: add N years to a date field

sahems.y.3
Hello,


Please attach your project (zip file without exe and dll) and describe, what exactly you want to do in your project.

Dmitry.