Qlikview Timestamp formatting upto microseconds? - qlikview

In qlikview I can get timestamp in milliseconds, by setting timestamp format as :-
SET TimestampFormat='MM/DD/YYYY hh:mm:ss.fff';
I want to know if there is a way to get time stamp in qlikview upto microseconds.

Formula to optain microseconds from TimeField:
((frac(TimeField) * 86400000) - floor(frac(TimeField) * 86400000)) * 1000 as Micro
And I would use this formula for formatting:
Timestamp(TimeField - (Micro/86400000000)) & Num(floor(Micro), '000') as TimeStamp

As far as I can determine from the QlikView help, there is no format specifier for microseconds, only for milliseconds.
If you need to obtain the microsecond value from a time, I quickly threw the below together (it can probably be done a bit neater). Here I assume your input time field is called TimeField. We can obtain the number of milliseconds using:
=((TimeField-num(date(floor(TimeField)))-
num(maketime(hour(TimeField),minute(TimeField),second(TimeField))))*24*60*60)*1000
For the sake of simplicity, I will call the above formula MillisecondCount. Then, using this field, we can then calculate the number of microseconds:
=floor(((MillisecondCount)-floor(MillisecondCount))*1000)
Finally, the full formula to obtain microseconds becomes:
floor(((((TimeField-num(date(floor(TimeField)))-
num(maketime(hour(TimeField),minute(TimeField),second(TimeField))))*24*60*60)*1000)
-floor(((TimeField-num(date(floor(TimeField)))-
num(maketime(hour(TimeField),minute(TimeField),second(TimeField))))*24*60*60)*1000))*1000)
You can then just format this with num() and append it to your time-stamp string.

Related

How to use Column value as Interval to increase date in Oracle SQL?

I have table named REFERENCE with columns TIME (timestamp), and ADJUST that stores varchar seconds values: 10, 13, 55, .. etc
I want to use the field ADJUST to increase value of TIME while making sure that ADJUST values are converted to seconds and not minutes or other units, something like:
SELECT
TIME AS START,
TIME + ADJUST AS END
FROM REFERENCE;
How to that?
I've tried using interval but it works only with explicit values, example:
TIME + INTERVAL '13' SECOND AS END
You can use numToDSInterval():
time + numToDSInterval(adjust, 'second')
It might be cleaner to explicitly convert the string to a number:
time + numToDSInterval(to_number(adjust), 'second')
If adjust always belongs to range 00-59, you can also use to_dsinterval():
time + to_dsinterval('0 00:00:' || adjust)
Seconds should be stored as number, why are they varchar (or probably varchar2)?
Other than that, the trick is to take an interval literal (which indeed requires a hard-coded string) and use arithmetic operations on it.
So, let's say time and adjust are your columns; time is in timestamp data type, and adjust is number, measured in seconds. (If it's string, you can convert it to number, explicitly, by wrapping it within to_number(); I will leave that out, since adjust should really be number data type to begin with.)
Then you can do something like this:
..... time + adjust * interval '1' second.
Here adjust can be 300, as in the example you gave under GMB's answer.

teradata SQL convert real to timestamp

I can't understand how to convert this type of real - 42389.520752314813 to timestamp.
I got this data from one source, but I need to convert it to normal timestamp format.
I think you have received wrong input data.
this type of timestamp is only occurring when Destination tool is excel and which has CELL as "Number" type, and during Copy-Paste of timestamp, destination field has Calculated it as Mathematical function. Please re-verify your source. I am sure about this mathematical calculation. please check the below sample of such data. So practically you cannot perform its reverse operation.
Hard to do without knowing what timestamp should be returned.
If the date is sourced from a SQL Server it might be '2016-01-22 12:29:53':
cast( date '1900-01-01' + myCol as timestamp(3))
+ (cast(86400 * (myCol mod 1) as dec(12,6)) * interval '00:00:01.000000' hour to second)
If it's from Excel it's two days earlier and you must start at '1899-12-30'

Convert DOUBLE column to TIMESTAMP in Firebird database

I have a Firebird database that saves the datetime field as a DOUBLE. I have created a ColdFusion datasource connection, so I can query the data remotely. While the rest of the data is being returned correctly, the datetime field is unreadable. I have tried using CAST and CONVERT to no avail. How can I convert this to a timestamp?
An example of the data stored is: 43016.988360
You can't just convert a DOUBLE PRECISION to a TIMESTAMP, not without explicitly defining how you want it mapped and writing that conversion yourself (or hoping there is an existing third-party UDF that does this for you).
A TIMESTAMP in Firebird is a date + time represented as an 8 byte value, where the date range is from January 1, 1 a.d. to December 31, 9999 a.d. and the time range is 00:00 to 23:59.9999 (so, 100 microsecond precision).
A DOUBLE PRECISION is - usually - the wrong type for storing date and time information, and as you haven't provided how that double value should be interpreted, we can't help you other than saying: there is no default method in Firebird to do this.
Based on the comments below, it looks like the value is a ColdFusion date value stored as double precision with the number of days since December 30th 1899, see also why is ColdFusion's Epoch Time Dec 30, 1899?. If this is really the case, then you can use the following for conversion to a TIMESTAMP:
select timestamp'1899-12-30 00:00' + 43016.988360 from rdb$database
Which will yield the value 2017-10-08 23:43:14.304. Using the value 43182.4931754 from the comments will yield 2018-03-23 11:50:10.354. That is a millisecond off from your expectation, but that might be a rounding/presentation issue, eg I get the exact expected date if I use 43182.49317539 instead.
I would strongly suggest you carefully test this with known values.

Convert TIMESTAMPL (timestamp long) to TIMESTAMP ends with 60

I am having an OData Service returning some DateTime values. They are saved in a table in the back end as TIMESTAMPL (with some other data).
Now there is the value 20160630084459.5000. With MOVE-CORRESPONDING into the et_entityset, where it is a TIMESTAMP. Because of the rounding, it gets 20160630084460, Since a the seconds must be between 00 and 59, this is not a valid value to return.
My main problem is, that my table has extremely much entries, so I need a performant way to fix this error.
Here is a way to convert it to what you want.
REPORT zzy NO STANDARD PAGE HEADING.
FORM convert_timestamp.
DATA(l_t1) = CONV timestampl('20160630084459.5000').
DATA: l_t2 TYPE timestamp.
l_t2 = l_t1.
WRITE / : l_t1, l_t2.
CONVERT TIME STAMP l_t1 TIME ZONE sy-zonlo INTO DATE DATA(l_date) TIME DATA(l_time).
CONVERT DATE l_date TIME l_time INTO TIME STAMP l_t2 TIME ZONE sy-zonlo.
WRITE / l_t2.
ENDFORM.
START-OF-SELECTION.
PERFORM convert_timestamp.
Here is the output.
20.160.630.084.459,5000000
20.160.630.084.460
20.160.630.084.459
You mention floor in your question but that is not what is happening. The value is rounded. If you simple do use FLOOR in your assignment from TIMESTAMPL to TIMESTAMP you will get the answer you want. If you have to use MOVE-CORRESPONDING, just do that first and then do a seperate assignment for the timestamp.
However, this means that 0:59.9 will get translated to 0:59 and not 1:00. If that missing second is OK for your application then just use the FLOOR command. If not it becomes more complicated and you will take a performance hit.

Convert time from seconds to hours, with rounding

I need to convert time from seconds to hours with 2 decimal rounding
PeriodLength contains time in seconds.
(c.PeriodLength)/3600. as Time
Returns time in hours but result is like 1.250000
and I need it to be 1.25.
Using standard SQL, you can convert it to a decimal. Something like:
select cast(c.PeriodLength / (60.00*60) as decimal(6, 2));
There are also database specific solutions, but you don't specify the database.
SET value = ROUND(value,2)
Note that this is generally used for statistical purposes, rather than monetary or time. However, it should work for what you are seeking.