Dears, I want to get last 7 days records from my stats. There is a date column in my data, but its type is "int" e.g., 20190102
anyone can advise how to get last 7 days records from my stats?
Related
I am select data from a table with different timestamps and I need to group the data by 7 days intervals without using the week keyword.
You can easily use the DAYS function and divide it by 7 like
GROUP BY DAYS(my_dt_column) / 7
See https://www.ibm.com/support/knowledgecenter/en/SS6NHC/com.ibm.swg.im.dashdb.sql.ref.doc/doc/r0000789.html
I want to convert Julian dates to normal dates (from JDE database). I run this query:
select to_date(to_char((DATE+1900000)),'YYYYDDD') from table ;
And I get the following error:
ORA-01848: day of year must be between 1 and 365 (366 for leap year).
I know it's because some dates are null or have no values.
Can anyone help me out on this please?
I have replicated your query and I tried with different values. Only if the date value is "0", you will get this error:
ORA-01848: "day of year must be between 1 and 365 (366 for leap year)"
So I thought that maybe you were interested in avoid the "0" values, and you can avoid it with a simple where, like this one:
SELECT to_date(to_char((DATE+1900000)),'YYYYDDD')
FROM table
WHERE DATE != 0;
Tableau is reading my dates wrong. I have 2 columns, Date and number for each day.
The date format is “yyyymmdd” i.e. (20160617) and per day number is integer. I am fetching this data directly from SQL server and my problem is, tableau is reading my dates wrong.
So I tried DATEPARSE() to convert my date.
My DATEPARSE function is : DATEPARSE(“yyyymmdd”,”Date”) , now after using DATEPARSE function, I get NULL for my dates.
Can anyone please help me why I get NULL for dates, my query returns 30-day data which is divided into per day count.
Sample after running the query on SQL
Date Per day number
20160617 215674
Tableau does not accept this date format and I applied DateParse(), which I guess is returning string since my date is null. I would ideally like to get the correct date so I can apply a trend line on my data.
Thanks in advance.
Cheers!
You aren't using DateParse() correctly. The second parameter, which you have as "Date", should be the name of the field you want parsed. So for example, if you store 20160617 in a field called my_date_as_integer, your function should be DateParse("yyyymmdd", [my_date_as_integer])
I am new to Cognos and I am trying to add a filter to a column that only allows rows that are in between Yesterday at 4 AM and today at 3 AM. I have a working query in db2 but when I try to add it to the filter in Cognos I get a parsing error. Also, I found in the properties that the data type for the column I am trying to filter to be Unknown (Unsupported) type. I started off by creating two Data Item Expressions for each time frame I am trying to limit the data by. But I got a parsing error on the first one:
[Presentation Layer].[Cr dtime]=timestamp(current date) - 1 day + 4 hour
This works in my db2 local test database but doesn't even compile in Cognos. I also tried casting the column into a timestamp but that isn't working either. Any help is appreciated. I also tried using the _add_days function but I still get a parsing error. Also sampling the column I get values that appear to be timestamps as this string: 2016-01-02T11:11:45.000000000
Eventually if I get the two filters working I expect the original filter to be close to this syntax:
[Presentation Layer].[Cr dtime] is between [Yesterday 4AM] AND [Today 3AM]
Here is your filter:
[Presentation Layer].[Cr dtime] between
cast(_add_hours(_add_days(current_date,-1),4),timestamp)
and
cast(_add_hours(current_date,3),timestamp)
This works because current_date in Cognos does not have a time component. If you were to cast it directly to a timestamp type you would see the time part of the date as 12:00:00.000 AM, or midnight. Knowing this we can then simply add how much time after midnight we want, cast as a timestamp type and use this in the filter.
I am working with PostgreSQL 8.4.4. I am calculating time difference between two Unix time-stamps using PostgreSQL's age function. I am getting the output as expected. The only thing I want is to convert the time difference in UPPERCASE.
For example,
select coalesce(nullif(age(to_timestamp(1389078075), to_timestamp(1380703432))::text,''), UPPER('Missing')) FROM transactions_transactions WHERE id = 947
This query giving the result as
3 mons 4 days 22:17:23
But I want this output to be like
3 MONTHS 4 DAYS 22:17:23
Note: I am using this for dynamic report generation purpose. So I cannot convert it to UPPERCASE after fetching from database. I want it to be in UPPERCASE at the time of coming from database itself, i.e., in the query.
PostgreSQL's upper() function should be use
SELECT upper(age(to_timestamp(1389078075), to_timestamp(1380703432))::text)
FROM transactions_transactions WHERE id = 947
as per OP's comment and edit
select upper(coalesce(nullif(age(to_timestamp(1389078075), to_timestamp(1380703432))::text,''), UPPER('Missing')))