9 Replies Latest reply: Mar 27, 2015 12:55 PM by Nagendra Babu

# subtract 120 days from date

Hello.

I have a problem, I need to subtract 120 days to a date and I can not.

Subtraction is a field that is not master calendar, I use a MAKEDATE (year, month, day) to create the date, but everything I use does not give correct results.

Anyone have any idea?

Thanks and regards

• ###### subtract 120 days from date

Hi,

All you have to do is just say    Date - 120.

Look what output it gives, if its number then you can try this.  Date(Date - 120).

What are the things you have tried?

Regards,

Kaushik Solanki

• ###### Re: subtract 120 days from date

Thanks, this just helped me workout some of my solutions, but i have a question, how can I display

Start date is = Today()?

Start date = 2012/11/02

Edzi

• ###### subtract 120 days from date

Hi there,

Why not use INTERVAL to subtract 120 days from your date?

For example:

Front end

Script

date(interval([YOUR DATE] - 120,'D'),'YYYY/MM/DD') as "NEW DATE"

Hope this helps,

Regards GJ

• ###### subtract 120 days from date

Hi,

=Date(makedate(2012,01,27)-120)

Thanks & Regards,

Parag Patil

• ###### Re: subtract 120 days from date

Thank you all for your responses.

My first question is not complete, I had an error.

I need to calculate the amount of the selected date minus 120 days. I can not make it work with any of your suggestions

Attached qvw.

thanks

• ###### Re: subtract 120 days from date

Hi Gabriel,

If you haven't figured it out already here's a solution that works well for me

Assume you create a date like so:

```LET zcurrDate = Date(MakeDate(Year(Today()), Month(Today()), Day(Today()))), 'YYYYMMDD');  //Result in this case is 20121002
```

to calculate a date going back n days

```LET zPrevdate = Date(Date#(\$(zcurrDate), 'YYYYMMDD')-n, 'YYYYMMDD'); //where n=120
```

Lets break the above down (inside to out):

```Date#(\$(zcurrDate), 'YYYYMMDD')-120 //Result after subtracting 120 days from 20121002 is 41064
takes string input so your date would essentially be in "string format" already, from what i see in terms of your data source in your QVW, but returns the date
in a "proper"date format that Qlikview can correctly manipulate, so subtracting 120 from the date will return a date in a number format i.e 41064 in this case

Putting the above Date# result into the "regular" Date function will convert the date as a number into a readable format i.e Date(41064) = 20120604

```

Works everytime for me, hope it does for you too and I hope my explanation (according to how I understand it) makes sense.

• ###### Re: subtract 120 days from date

Hi

Try this

sum({<datefield={"=\$(=date(today()-30))"}>}amount)

• ###### Re: subtract 120 days from date

Use Date(Num(MAKEDATE (year, month, day) )-120) then you will get the date before 120 days.

• ###### Re: subtract 120 days from date

=date(today()-1