Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

calc date for data load[load editor]

Hi comm,

i want to load data from the last 3 days.

Thats why i want to get today - 3 days to get the date x. And with datex i want to load data into Qlik Sense!

FROM Dashboard.dbo."QLIK_TF_SELL";

WHERE Date(Date#(Date_new,'YYYY.MM.DD')) > Date(Date#('x', 'YYYY.MM.DD'))

and x like i said is today -3d!!!

Can i calc this with var in the script?

thanks for help and advices in advance

-Eric

19 Replies
Not applicable
Author

SQL

vinieme12
Champion III
Champion III

can you try below

FROM Dashboard.dbo."QLIK_TF_SELL"

WHERE CONVERT(INT,Date_new) > GETDATE()-3 ;


Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Not applicable
Author

Sorry for late response,

had something else to do!

First why to int?

and also there is the error "explicit conversion of the date data type to int is not allowed."

vinieme12
Champion III
Champion III

Mathematical operation with a date such as addition or subtraction will return an integer value

so getdate() - 3 , will return an int value

We are converting your Date_new value to INT as both comparing values should be in same format.

FROM Dashboard.dbo."QLIK_TF_SELL"

WHERE CONVERT(INT,CONVERT(VARCHAR(10),Date_new)) > GETDATE()-3 ;

OR

FROM Dashboard.dbo."QLIK_TF_SELL"

WHERE CONVERT(INT,CONVERT(VARCHAR(MAX),Date_new)) > GETDATE()-3 ;


Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Not applicable
Author

thanks for ur great support and now i understand it !

But i have a date coloumn with 2016-09-20

but getting following error:

ErrorMsg: error with converting varchar-value 'Sep 15 2016' into int-data typ.



I dont understand why I have so much problems with converting and restrict data load

vinieme12
Champion III
Champion III

Happens with all

FROM Dashboard.dbo."QLIK_TF_SELL"

WHERE CONVERT(INT,CONVERT(VARCHAR(10),Date_new,101)) > GETDATE()-3 ;

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Not applicable
Author

I think this is right way but wrong format get error with.

converting problem varchar ' 09/15/2016 ' into in datatyp.

maybew change 101 so format is '2016-09-15' like in my db ?

Where do u get these infos! Pls send link!

must leave now. i ll answer tomorrrow!

BB and thanks

vinieme12
Champion III
Champion III

https://www.techonthenet.com/sql_server/functions/index_alpha.php

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
lakshmikandh
Specialist II
Specialist II

Hi Eric,

please try this,

FROM Dashboard.dbo."QLIK_TF_SELL"

WHERE Cast(CONVERT(VARCHAR(10),Date_new,112) as int) > Cast (Convert(varchar(10),GETDATE()-3,112) as int) ;

This convert will change the date into '20160928' this format

Not applicable
Author

Thanks for ur time spend in this problem.(u will get a lot of likes) Thanks for this solution works very well!!!

Love this Community!!