extract time and date from field qlikview - time

i have this kind of data
Check_in
18/11/2019 10:32:01
18/11/2019 10:12:28
18/11/2019 09:32:57
18/11/2019 09:28:58
18/11/2019 09:28:53
now i want to extract date and time from this field
i.e.
date time
18/11/2019 10:32:01
i try this in script but this does not working
Time(Fromtime) as check_in
when i try to format date on excel this shows like this. sames dates are converted and some are not
files
https://www.dropbox.com/s/xnxaprguz7x3fua/zooho%20dash.qvw?dl=0
https://www.dropbox.com/s/3yb2zm7plaf9o6p/excell_timein_sheet.xlsx?dl=0

The main trick here is that you want to use DATE#(), TIME#(), TIMESTAMP#() because you know the format of the inputs and want to force Qlik to recognise them as dates and times
CHECK_INS:
load *,
date(floor(TIMESTAMP)) as DATE2,
time(TIMESTAMP) as TIME2
;
load *,
date#(subfield(check_in,' ',1),'DD/MM/YYYY') as DATE,
time#(subfield(check_in,' ',2),'hh:mm:ss') as TIME,
Timestamp#(check_in,'DD/MM/YYYY hh:mm:ss') as TIMESTAMP
;
The subfield() is to split the Date and Time section based on the location of the space.
The other option is to first TIMESTAMP#() the whole timestamp and then use the date() and time() functions. You need the floor() to remove the time portion from the dates otherwise you'll see what look like multiple entries for the same date, but they are just timestamps formatted as dates so still remember their time portion.

Related

Applying case when date

I have to set the start date as 01-01-year which would be pulled from the expense date field. I have written the below query
select to_date(extract(year from rpt.expense_date),'yyyy') from rpt
How can I set the date to 01-01-year which would be pulled from above query.
Thanks in advance.
Use TRUNC to truncate to the start of the year:
SELECT TRUNC(expense_date, 'YY') FROM rpt
You can just truncate the date value:
trunc(rpt.expense_date, 'YYYY')
By default the trunc() function truncates to midnight on the specified day, equivalent to trunc(<date>, 'DD'), but you can use other elements.
In your code:
to_date(extract(year from rpt.expense_date),'yyyy')
you are only supplying the year element to to_date(); in that situation the other date elements default to the first day of the current month - so today that would give you June 1st in that year, not January 1st. That's hidden away a bit in the documentation:
If you specify a date value without a time component, then the default time is midnight. If you specify a date value without a date, then the default date is the first day of the current month.

Reformat date in SQL Loader

I am loading Oracle tables using SQL Loader and I have an issue with date formats. The CSV files with the data contain strings in the format YYYY-MM-DD HH:MM:SS, but the Oracle tables require date format of DD-MON-YY.
I am currently going through the CSV files line by line to look for and reformat any dates before the load, but the files can reach 10M+ rows and this can be a pretty slow process. Does SQL Loader allow date reformatting in the load?
I'm looking for something like
LOAD DATA
INFILE 'data.csv'
TRUNCATE
INTO TABLE data
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS
(
COL1,
COL2,
CREATED_DATE DATE 'DD-MON-YY',
LAST_UPDT_DATE DATE 'DD-MON-YY
)
I've read suggestions that this DATE command can format dates automatically but has given no luck so far.
Assuming created_date and last_updt_date are actually defined as date in the database, they don't have a format. They're stored in an internal packed binary format that is not human readable.
Your control file needs to specify the format of the strings in the flat file that represent the date. You say the format is "YYYY-MM-DD HH:MM:SS" but that doesn't make sense. Minutes are MI not MM so I assume that is a type. HH is a 12 hour time format but that doesn't make sense without an AM/PM indicator. So I'm guessing your strings are using a 24 hour time format which is HH24. So my guess is that you want
CREATED_DATE DATE 'YYYY-MM-DD HH24:MI:SS',

Oracle select date without time and keep date as data type

I have a column name 'Cos_Date' with value like 14APR2017:00:00:00.
However, for a new column name 'Arrival_Date', I would like to keep the date information but omit time, and keep the data type as Date but not Character. Ex, 14APR2017.
I have tried:
select TO_CHAR(Cos_Date, 'DD-MON-YYYY') ARRIVAL_DATE
But it will delete time information, but data type turns to Character.
I search on this site, and tried both:
select TO_DATE(TO_CHAR(Cos_Date, 'DD-MON-YYYY'), 'DD-MON-YYYY') ARRIVAL_DATE
and:
select TRUNC(Cos_Date) ARRIVAL_DATE
But it will not omit time information.
Can I try something else?
Thank you!
You can't "omit" the time portion of a DATE column in Oracle. The DATE data type always contains a time component. If you don't want to see the time, don't display it, e.g.,
SELECT TO_CHAR(TRUNC(Cos_Date),'DD-MON-YYYY') FROM dual;
In Oracle there is no date data type that has only a year-month-day component.
The DATE data type is stored internally as 7- or 8-bytes which always has year (2-bytes), month (1-byte), day (1-byte), hour (1-byte), minute (1-byte) and second (1-byte).
The TIMESTAMP data type also has fractional seconds (and can also have a time zone).
Can I try something else?
No, you either use a VARCHAR2 string or use a DATE or TIMESTAMP and accept that it has a time component.
Selecting date values without time:
SELECT date_col
FROM table
WHERE TO_CHAR (date_col, 'HH24:MI:SS') = '00:00:00';

How to load files using SQLLDR with date format as yyyymmddhhmmss?

I need to load a table with a .csv file which contains date "20140825145416".
I have tried using (DT date "yyyymmdd hh24:mm:ss") in my control file.
It throws an error as ORA-01821: date format not recognized
I require the data in table as "MM/DD/YYYY HH:MM:SS".
Sample data : 20140825145416
thanks in advance.
Well, I would be remiss if I did not point out that the correct answer is to never store dates as VARCHAR2 data, but make it a proper DATE column and load it like this:
DT DATE "YYYYMMDDHH24MISS"
Formatting is done when selecting. It will make your life so much easier if you ever need to use that date in a calculation.
That out of the way, If you have no control over the database and have to store it as a VARCHAR2, first convert to a date, then use to_char to format it before inserting:
DT CHAR "to_char(to_date(:DT, 'YYYYMMDDHH24MISS'), 'MM/DD/YYYY HH24:MI:SS')"
Note 'MI' is used for minutes. You had a typo where you used 'MM' (months) again for minutes.
I know it's already been said in the previous answer, but it's so important, it's worth repeating. Do not store dates as varchars !!
If your DT column is timestamp then this might work
DT CHAR(25) date_format TIMESTAMP mask "yyyymmddhhmiss"
I used something like this in external tables. Maybe this might help
https://docs.oracle.com/cd/B19306_01/server.102/b14215/et_concepts.htm
and
https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:8128892010789

How to add conditional date filter to SQLite export script

I am using a bash script to export data from the songs table in a Clementine db:
#!/bin/bash
/usr/bin/sqlite3 /home/username/.config/Clementine/clementine.db <<!
.headers off
.mode csv
select filename from songs where lastplayed > -1;
!
The date information shown in the column lastplayed is expressed in unix time (example:1479607204). Where a record has no date, the field's data is shown as -1.
Using the above script correctly displays all entries in the songs table that have any lastplayed date (lastplayed > -1).
If instead, I want the date filtered based on number of days elapsed (using today's date, so assume the NOW statement is used in some way), how would I modify the SELECT line above to calculate and filter output? I reviewed the SQLite manual page for date/time but as a newbie I could not solve how to use its syntax in the script.
Assume the filter lists only those records for which there is a date, and the unix date is at least 10 calendar days earlier than today.
To do comutations with dates, add the appropriate modifiers to some date function. To convert a date into the Unix format, use strftime() with the %s format:
sqlite> SELECT strftime('%s', 'now', '-3 days');
1479410717
And to make the comparison work, you have to convert the resulting string into a number:
SELECT filename
FROM songs
WHERE lastplayed > CAST(strftime('%s', 'now', '-3 days') AS INTEGER);

Resources