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: 
Not applicable

Date#() function: Worng type of output

Hi all,

I'm trying to convert a text date into its numeric value using the Date#(...) function but for some reason it is not working properly.

--------------------------------------------------------------------------

Here is the piece of code I'm using for testing:

--------------------------------------------------------------------------

LET vMinDateText = MakeDate(2015,03);

LET vMaxDateText = Today(1);

LET vMinDate = Date#('$(vMinDateText)','DD/MM/YYYY');

LET vMaxDate = Date#('$(vMaxDateText)','DD/MM/YYYY');

TRACE >>> vMinDateText: $(vMinDateText);

TRACE >>> vMaxDateText: $(vMaxDateText);

TRACE >>> vMinDate: $(vMinDate);

TRACE >>> 'vMaxDate: $(vMaxDate);

--------------------------------------------------------------------------------------

The output displayed in the running script window is:

--------------------------------------------------------------------------------------

>>> vMinDateText: 1/03/2015

>>> vMaxDateText: 20/05/2015

>>> vMinDate: 1/03/2015

>>> vMaxDate: 20/05/2015

As you can see the data type stays the same. vMinDate and vMaxDate are texts instead of numbers.

Any idea on what I have been doing wrong ?

Thanks a lot for your help

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

The Date# function merely turns a string into a date. It gets the default date format of your document unless you use the date() function to specify a format explicitly. If you want a number then use a function that returns a number (like the num function) on it: LET vMinDate = num(Date#('$(vMinDateText)','DD/MM/YYYY'));


talk is cheap, supply exceeds demand

View solution in original post

4 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

The Date# function merely turns a string into a date. It gets the default date format of your document unless you use the date() function to specify a format explicitly. If you want a number then use a function that returns a number (like the num function) on it: LET vMinDate = num(Date#('$(vMinDateText)','DD/MM/YYYY'));


talk is cheap, supply exceeds demand
Colin-Albert
Partner - Champion
Partner - Champion

Date#() formats input text strings into a dual date value.

To format the output date you need to use Date() to convert the output value to the required format.

This post by Henric Cronstrom  hic‌ has a clear explanation on formatting dates for input and output  Get the Dates Right

Not applicable
Author

Thanks a lot Gysbert.

I indeed needed a number so I used the num fonction as you advised and it is working fine now.

Not applicable
Author

Thanks for sharing the Get the dates Right post