Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
qingkong
Contributor II
Contributor II

How to calculate the date

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

6 Replies
rubenmarin

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 II
Contributor II
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

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

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 II
Contributor II
Author

Thank you for solving my problem successfully