Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
qingkong
Contributor III
Contributor III

How to calculate the date

I want to subtract date2 from day, but it shows an error1.JPG2.JPG

6 Replies
rubenmarin
MVP
MVP

Hi, it's not clear what you need to do, to giv some tips:

- You can use Date#() to tell input format of a date, Date() is to set the output format. so if your language format date is set to DD/MM/YYYY and you have a date like 20110223 you can use Date(Date#(DateField,'YYYYMMDD')) and it will be shown as 23/02/2011.

- You can't use fields created in the current LOAD, you can use a precedent load to use the calcualted fields on previous steps, so to substract date it could be:

LOAD
  *,
  Now()-date as day
;
LOAD
  Material,
  Num(... as date
...
;

 

qingkong
Contributor III
Contributor III
Author

Thank you for your reply. I would like to subtract The GR date from The current date.

How do I write this code

3.JPG

Iswarya_
Creator
Creator

Hi @qingkong ,

Try like this in script:

=Date([GR Date],'YYYY/MM/DD')-Date(Today(),'YYYY/MM/DD') as Day

Anil_Babu_Samineni
MVP
MVP

I would prefer to use Interval in this case

Ex, =Interval(Date([GR Date])-Date(Today()), 'DD') as Day

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
rubenmarin
MVP
MVP

Hi, [GR Date] is left-aligned, that means it's being stored as a text, not as a number (a date is a number).

First convert it to Date with Date(Date#([GR Date], 'YYYY/MM/DD'))

To substract you can just do: Today()-Date(Date#([GR Date], 'YYYY/MM/DD'))

qingkong
Contributor III
Contributor III
Author

Thank you for solving my problem successfully