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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
hansdevr
Creator III
Creator III

How to substract a second (or a minute) from a date field?!?

I need to fill a new field in a table with the date from a field in a previous record.

The latter contains a date in the following format: yyyy-mm-dd hh:mm:ss:xxxxxxx (not sure what those xx's are). Example:

2014-11-14 02:00:50:3930000

I need to use that value in a (new) field in the current record, but I need to substract a second or a minute from that value.

I have been searching, but couldn't find an answer...

1 Solution

Accepted Solutions
sunny_talwar

Try this to subtract a second:

=Timestamp(Timestamp#('2014-11-14 02:22:50:3930000', 'YYYY-MM-DD hh:mm:ss:fff') - Interval#('1', 'ss'), 'YYYY-MM-DD hh:mm:ss:fffffff')

To subtract a minute, try this:

=Timestamp(Timestamp#('2014-11-14 02:22:50:3930000', 'YYYY-MM-DD hh:mm:ss:fff') - Interval#('1', 'mm'), 'YYYY-MM-DD hh:mm:ss:fffffff')

View solution in original post

27 Replies
Not applicable

sunny_talwar

Not sure what you mean when you say you have to subtract a second or a minute? In your above example: 2014-11-14 02:00:50:3930000 what would be the output you would be expecting?

Not applicable

hansdevr
Creator III
Creator III
Author

Hi Harshita and thank you for your swift reply.

I have looked at that link, and unfortunately, it gives an example on how to calculate a difference, not how to substract a value (of a second or a minute).

Thanks anyway!

hansdevr
Creator III
Creator III
Author

If the first value is 2014-11-14 02:22:50:3930000 then the second value should be 2014-11-14 02:22:49:3930000

(which subtracts one second) OR the outcome should be 2014-11-14 02:21:50 3930000, which is the subtraction of a minute.

sunny_talwar

I think you need to create a master Time Table: The Master Time Table

This works as a master calendar, where you create missing time values. You can decide your smallest denomination to be Seconds or Minute.

HTH

Best,

Sunny

hansdevr
Creator III
Creator III
Author

Actually, I want to do the subtraction using a variable.. It's not a matter of a 'missing' time value - I just want to do a calculation on the value of a field within a record..

Not applicable

First set up format like


for Minutes Calculation


vNowTime= num(timestamp#('2015/09/07  11:55:25 PM','YYYY/MM/DD  hh:mm:ss TT'));
vPrevTime = num(timestamp#('2015/09/07  11:55:25 PM','YYYY/MM/DD  hh:mm:ss TT'));

sum(vNowTime - vPrevTime )

or

vNowTime= num(timestamp#(INVTIME,'YYYY/MM/DD  hh:mm:ss TT'));

vPrevTime = num(timestamp#(INVTIME,'YYYY/MM/DD  hh:mm:ss TT'));

for Days Calculation

sum(Date(Today())- date(date#(INVDATE,'YYYYMMDD'),'DD/MM/YYYY'))


hope it works

hansdevr
Creator III
Creator III
Author

A bit like AddMonths(EndDate,-1), but then for a minute or a second, if you catch my drift..