Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More
Highlighted
KevinG
New 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

Tags (4)
2 Solutions

Accepted Solutions
Partner
Partner

Re: Subtract a date from today's date

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
];
Plees ekskuse my Swenglish and or Norweglish spelling misstakes

View solution in original post

KevinG
New Contributor

Re: Subtract a date from today's date

Hi Vegar

Many thanks, this worked for me, 

today()- BLOTLOT_CREATED as "AgeDays"

View solution in original post

2 Replies
Partner
Partner

Re: Subtract a date from today's date

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
];
Plees ekskuse my Swenglish and or Norweglish spelling misstakes

View solution in original post

KevinG
New Contributor

Re: Subtract a date from today's date

Hi Vegar

Many thanks, this worked for me, 

today()- BLOTLOT_CREATED as "AgeDays"

View solution in original post