Skip to main content
Announcements
Do More with Qlik - Qlik Cloud Analytics Recap and Getting Started, June 19: REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
KevinG
Contributor
Contributor

Subtract a date from today's date

Hi All

I am new to QV, so please bear with me, 

I need to calculate the age of stock items, so, in the load script i want to subtract the stock created date (dd/mm/yy) from the today (run date).

how can i achieve this please.

Many thanks

2 Solutions

Accepted Solutions
Vegar
MVP
MVP

Just substract the two dates and you will get no of days. You can also use the AGE() function to get the age in years.

 

SET DateFormat='DD/MM/YYYY';  //Environmental variable 

LOAD *,
today()-CreateDate as AgeDays,
Age(today(), CreateDate) as AgeYears
INLINE [
CreateDate,Stock,last_name
14/03/2019,OPY,219.09
16/12/2018,LVS,51.49
17/10/2018,CBZ,824
23/02/2019,COTV,3.5
13/09/2018,ESGU,5.34
31/03/2018,TAST,450.72
12/06/2018,STE,6.96
23/07/2018,SAFM,2.88
31/10/2018,PAY,1.93
06/12/2017,PKI,7
];

View solution in original post

KevinG
Contributor
Contributor
Author

Hi Vegar

Many thanks, this worked for me, 

today()- BLOTLOT_CREATED as "AgeDays"

View solution in original post

3 Replies
Vegar
MVP
MVP

Just substract the two dates and you will get no of days. You can also use the AGE() function to get the age in years.

 

SET DateFormat='DD/MM/YYYY';  //Environmental variable 

LOAD *,
today()-CreateDate as AgeDays,
Age(today(), CreateDate) as AgeYears
INLINE [
CreateDate,Stock,last_name
14/03/2019,OPY,219.09
16/12/2018,LVS,51.49
17/10/2018,CBZ,824
23/02/2019,COTV,3.5
13/09/2018,ESGU,5.34
31/03/2018,TAST,450.72
12/06/2018,STE,6.96
23/07/2018,SAFM,2.88
31/10/2018,PAY,1.93
06/12/2017,PKI,7
];
KevinG
Contributor
Contributor
Author

Hi Vegar

Many thanks, this worked for me, 

today()- BLOTLOT_CREATED as "AgeDays"

Adri7
Contributor
Contributor

Hi! I have a similar problem... I also need to calculate the number of years between today() and another date and I'm putting qlik to read the function from a google sheet file. All functions seem to work fine but this in particular is giving me some trouble. 
I wrote:

Age(Today(), [FECHA_NACIMIENTO])

I don't know what is wrong with it. If you get some ideas I would really appreciate to know. Thanks in advance!