Thanks for the posts.
Unfortunately, just using the Date function is not producing consistent results.
I am using this QlikView script to transform data imported from a Firebird database, so I think I need to understand if there are any implicit conversions happening.
Here is a typical transfomation statement that I am using for a date (as I don't want any zero length strings in the field)
If(DATE_SETUP = '', Null(), DATE_SETUP) AS LeadDate
Please check the field is in date format or simply text?
Goto Document properties --> Tables --> Check the Tag for the Field "LeadDate". If tag has $number then probably it is in date format. Then use
If(DATE_SETUP = '', Null(), Date(DATE_SETUP)) AS LeadDate
No $number tag you need to convert it in to date format by using date# function.
To use date# function you need to analyse in which format it is getting loaded to qlikview.
MM/DD/YYYY or DD/MM/YYYY or DD-MM-YYYY or MM-DD-YYYY
If(DATE_SETUP = '', Null(), Date(Date#(DATE_SETUP, "MM/DD/YYYY"))) AS LeadDate
The time portion is just formatting - added by either the ODBC or by QlikView in the load phase.
QlikView does not have any data types (See this article). If it is a number and you have used the floor function, you are all set. You should/could use a Date() function on top of it to get the formatting right, but this is almost just "cosmetics". All numeric evaluations and sorting are based on the number you created with the Floor() function.
So, if you want to debug, and see what goes on, format it as a number instead: Num(DATE_SETUP).
And the NULL test is better made with
If(Len(Trim(DATE_SETUP))>0, DATE_SETUP) AS LeadDate, or
If(IsNum(Date#(DATE_SETUP)), Date#(DATE_SETUP)) AS LeadDate
This way you also catch values that contain spaces.
goodmorning. replying just not to open a new thread... i'm importing from a database where date and time are 2 different columns (i.e. for each day/date i have as many rows as records are acquired through the timeline); i'd like to concatenate i have to do calculations over another DB where the field "time" has all the parameters (DD/MM/YYYY hh:mm). how can i do that, i.e. not only concatenate characters but obtain a sort of numeric field to use with calculations? thanx
If you use the interpretation functions, you will get numeric values that you can add and subtract. Hence, you should use
Date#(DateField) + Time#(TimeField)
to get the correct timestamp number. Then you can wrap this in a formatting function to make it look good:
Timestamp( Date#(DateField) + Time#(TimeField), 'DD/MM/YYYY hh:mm' )