I want to show all dates onward when searching dates. For eg. i searched 2012-12-24, all dates going forward will appear.
Here's my query right now that can search the exact date only and not including date onward.
SELECT *
FROM user u
where cast(u.start_date as varchar) = '2012-12-24'
Use an inequality:
SELECT *
FROM user u
WHERE u.start_date >= '2012-12-24';
Related
I am creating a tableau dashboard and it should load data according to the date the user enters. This is the logic that I am trying.
select distinct XX.ACCOUNT_NUM, (A.TOTAL_BILLED_TOT-A.TOTAL_PAID_TOT)/1000 arrears, ((A.TOTAL_BILLED_TOT-A.TOTAL_PAID_TOT)/1000 - XX.SUM_BILL ) TILL_REF_JUL20
FROM
(
select /*+ parallel (bill ,40 ) */ distinct account_num, sum(INVOICE_NET_mny + INVOICE_TAX_mny)/1000 SUM_BILL
from bill
where account_num in (Select account_num from MyTable)
and trunc(bill_dtm) > ('07-Aug-2021') –-Refmonth+1 month and 07 is a constant. Only month and year is changing
and cancellation_dtm is null
group by account_num
)xx , account a
where xx.ACCOUNT_NUM = A.account_num
Here is what I tried. First created a parameter called ref_Month. Then created a calculated field with this.
[Ref_Month]=MAKEDATE(DATETRUNC('year',(DATEADD('month', 1, [Ref_Month])), 07))
But I am getting an error. I am using a live connection. Is there any method to achive this?
I don't understand what this statement is trying to do:
[Ref_Month]=MAKEDATE(DATETRUNC('year',(DATEADD('month', 1, [Ref_Month])), 07))
If Ref_Month is a date, which it has to be for DATEADD to be a valid operation, why not make it the 7th of whatever starting month and year you are starting with? Then DATEADD('month',1, [Ref_Month]) will be a month later, still on the 7th. So you don't need DATETRUNC or MAKEDATE at all.
That said, how, when, and where are you trying to COMPUTE a PARAMETER,
let alone based on itself?
I'm working on making a replica of sheet1 on to another sheet2 (same document), and query() worked fine until the column i want to filter are formula cells (LONG ones each with query, match, etc).
What i want to do is filter the rows in sheet1 where the event date in column M is upcoming (there are more filter conditions but just to simplify this is the main problem).
I don't want the rows where the date is either empty, in the past (various date formats), or where the formula give a result of empty string "".
The formulas i've tried (which gives error) - note i'm just selecting 2 columns for testing:
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND DATEVALUE(M)>TODAY() ",0)
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND M>TODAY() ",0)
This formula doesn't give error but doesnt show correct data - shows all data except Jan 2017 - August 7 2017:
=FILTER(sheet1!A3:N, sheet1!I3:I="Singapore", sheet1!M3:M>TODAY())
This formula gives empty output:
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND M='22 August' ",0)
There's no today() in Query. Use now() instead:
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND M > now() ",0)
Or if you want now() without time(equivalent to TODAY()), use:
todate(now())
For this to work, provided you have all the correct dates in M in any format, which Google sheets recognises (i.e., the formula bar shows the correct date or time) regardless of the actual string. If not, You should manually convert all those remaining dates to correct format. The correct format of date to be entered in the query formula is date 'yyyy-mm-dd'. It doesn't matter what format the date is in sheets ( as long as Google sheets recognises this), but the actual formula must only contain date in this format for comparison. For example , to find all dates less than 31,August, 2017,
=query(A2:B6, "select A where A < date '2017-08-31'")
You can use this to figure out all the dates, which Google doesn't recognise: N1:
M:M*1
If you get an error in the helper column N, then those dates are not recognised. Even if you did not get error, it is possible that Google sheets mis-recognizes the date. There is also a more specific function:
=ARRAYFORMULA(ISDATE(M:M))
References:
Scalar functions
I am trying to search data between two dates, but it retrieving old data where not in the range i gave? kindly advice me how to re-write the below query logic
select *
from Users
where TO_CHAR(Users.lastloggedindate,'dd-MON-yy HH.MI.SS') between '17-JAN-17 07.16.55' and
'18-JAN-17 09.20.22';
Try using to_date() instead of to_char(), to convert the two points of the range into dates against which your logged in date can be compared:
select *
from Users
where Users.lastloggedindate between to_date('2017-17-01 07:16:55', 'YYYY-DD-MM HH24:MI:SS') and
to_date('2017-18-01 09:20:22', 'YYYY-DD-MM HH24:MI:SS');
I have a button that when it is clicked I want it to select the last 14 days. This means that if today's date is 2014-03-12, I want it to select all dates between 2013-02-26 and 2014-03-12.
I have a time_table with the fields KEY_timestamp (yyyy-mm-dd), year, month, day.
In my button I have an action Select in Field, with the field KEY_timestamp and I have a Search String which looks like
=if(
now() - 14 < KEY_timestamp,
KEY_timestamp
)
Now, to tell you the truth I have no idea how to go about this, and my experience with Qlikview is limited at best... I hope somebody can point me in the right direction. I tried Googling this but I've been unsuccessful so far.
In the search string type only this line:
='>' & date(now()-14) & '<= ' & date(now())
If it didn't work properly, add this line in your script:
date(KEY_timestamp) as KEY_timestamp_formatted
and then replace your select in field with the new column
Iam struggling to get all dates from now (all dates from today or the future).
Unfortunately my dates are in this format: '%d%m%Y %H:i' (08.06.2013 12:00)
I tried a couple of things, the last was:
SELECT * FROM `events` WHERE DATE_FORMAT(SUBSTRING(enddate,1,9),'%Y%m%d') >= DATE_FORMAT(CURDATE(),'%Y%m%d')
I thought this would convert into: (when date = 27.08.2013)
SELECT * FROM `events` WHERE 20130827 >= 20130608
But its now working... I get too much results :-/
Any help would be appreciated...
Thanks!
You should try using STR_TO_DATE (reference).
SELECT * FROM `events` WHERE STR_TO_DATE(enddate, '%Y.%m.%d') >= CURDATE();
STR_TO_DATE parses the string according to given format ('%Y.%m.%d' in your case) and returns a date string that can be used with MySQL. Once converted, you can freely compare it against other date values or functions like CURDATE. You should read the documentation for more details.
In the longer run, you will be better off using actual DATE and DATETIME columns.