Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
devrajR
Contributor III
Contributor III

Date Conversion Issue

Hi,

I have a date column from which I derive two new columns: Day and LastDay of the month. The Datatype is $numeric$timestamp. How to I convert it to $numeric$integer? 

I tried using num(Day), but it converts the day to some random 5 digit number. For eg: Day for 22/04/2022 is converted to 44671, due to which I am getting issues in performing arithmetic operations on the day field.

Any suggestions would be helpful.

 

Thanks in advance,

Devraj

Labels (1)
1 Solution

Accepted Solutions
devrajR
Contributor III
Contributor III
Author

Thanks for your help! I was using Day() function then store in a table and then perform operations using num() which was giving the error. Now I have directly done operations using date() on day and monthend values and it works fine. 

 

Thanks to all who replied! 🙂

View solution in original post

9 Replies
Or
MVP
MVP

 I'm not following as to what your issue is. That number isn't random, it's the numeric value of the date in question.

If you're trying to convert this to some sort of numeric format, you can use e.g.

Year(Date) * 10000 + Month(Date)*100 + Day(Date)

Or whatever other format you want as derived from the original date.

devrajR
Contributor III
Contributor III
Author

For 20/04/2022, I need the value of day i.e. 20 in a new column, right now I am getting 44671. How do I get just 20 in a new column. I used Day(20/04/2022) and it gave me 20, but the data type was $numeric$timestamp. I am not able to do arithmetic operations on that.

 

devrajR
Contributor III
Contributor III
Author

I need to get the percent value by dividing the day number and last day of the month.

 

Date Day MonthLastDay Percent
20/04/2022 20 30 66.67%
21/04/2022 21 30 70.00%
22/04/2022 22 30 73.33%
23/04/2022 23 30 76.67%
vinieme12
Champion III
Champion III

Use the Day() function

Day(Date) as Day

Day(monthend(Date)) as MonthLastDay

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
devrajR
Contributor III
Contributor III
Author

I have tried the same thing, but for percent when I do (Day / MonthLastDay) it doesn't give me proper values. For 20th April 2022 the calculation that happens in the background is 44671 / 44681 = 0.9997. But I need, 20 / 30 = 0.6667. I think it is because the datatype for Day(Date) and Day(monthend(Date)) is saved as $numeric$timestamp

Or
MVP
MVP

I don't quite follow - why can't you perform an arithmetic operation on the day() value? It's numeric, so shouldn't be a problem.

hic
Former Employee
Former Employee

I suggest you read about how the Qlik dates work:
https://community.qlik.com/t5/QlikView-Documents/QlikView-Date-fields/ta-p/1484786
https://community.qlik.com/t5/Design/The-Date-Function/ba-p/1463157

But in short:
* The 44671 isn't random. It is the date serial number. Same as Excel.
* Day(Date) will return 20, for the 20th of the month.
* Day(MonthEnd(Date)) will return the number of days in the month.

So, Day(Date) / Day(MonthEnd(Date)) should do the trick.

Or
MVP
MVP

Load Day(Today()) as Day, Day(MonthEnd(Today())) as MonthEnd, Day(Today()) / Day(MonthEnd(Today())) as Ratio
AutoGenerate(1);

Or_0-1678887266311.png

 

devrajR
Contributor III
Contributor III
Author

Thanks for your help! I was using Day() function then store in a table and then perform operations using num() which was giving the error. Now I have directly done operations using date() on day and monthend values and it works fine. 

 

Thanks to all who replied! 🙂