I do a select and its working perfect but I want to change it to a select with a from and to date, how would I change my sample to do this? I will get the date from a richfaces calender,
I have a filter on my page that selects all the values for the sql select. so I want to a start and end date to that filter and only get the results between those dates. only "dd/MM/yyyy" can be used as its not necessary for the time
example of select:
myList = database.createQuery("SELECT t FROM Logging t WHERE t.No = :No and t.customer = :customer and t.project = :project and t.task = :tasks").setParameter("No", getNo()).setParameter("customer", getCustomer()).setParameter("project", getProject()).setParameter("task", getTask()).getResultList();
This resolved it for me: and t.date BETWEEN :startDate AND :endDate at the end and then just added the setParameter with the values I get from richfaces calender and works perfect!
Related
I have similar problem statement of (PowerBI/DAX: Unable to correctly compare two dates)
where I'm selected the start date and end date from slicer and wrote DAX for the measures as
Start_Date = CALCULATE(Min('Calendar'[Date]),ALLSELECTED('Calendar'))
End_Date = CALCULATE(Max('Calendar'[Date]),ALLSELECTED('Calendar'))
And I use them to compare with a column and return TRUE or FALSE.
IsTrue_Flag = IF(table[prod_date]>=[Start_Date] && table[prod_date] <= [End_Date], TRUE, FALSE)
But all my values are turning as TRUE which is not the case.
Where did I go wrong with the DAX? please help
I currently have a QUERY function which is set up based on a start date cell and an end date cell, formula as below:
=QUERY(Haulage!$A$3:$L$29," Select * Where A >= date """&text('2022 Stats'!S1, "yyyy-mm-dd")&""" AND A <= date """&text('2022 Stats'!T1, "yyyy-mm-dd")&"""")
This is working fine but I would like to adapt it so I can also narrow the query down further with the use of a dropdown. I have the following IF formula for this:
=IF('2022 Stats'!V1="All TOCs",""," AND LOWER(K) = LOWER('"&'2022 Stats'!V1&"') " )
This seems to yield the correct results but I am struggling to get the two to work together......
Link to sheet: https://docs.google.com/spreadsheets/d/1wTWuvFwMTqJ-sjIZbXWpGOS1WKwpODj2R8KAzqlqkuw/edit?usp=sharing
Try:
=QUERY(Haulage!A3:L29,
"where A >= date '"&TEXT('2022 Stats'!S1, "yyyy-mm-dd")&"'
and A <= date '"&TEXT('2022 Stats'!T1, "yyyy-mm-dd")&"'"&
IF('2022 Stats'!V1="All TOCs",,"
and lower(K) = '"&LOWER('2022 Stats'!V1)&"'"))
I want to compare from_date and to_date with date_order using search orm in odoo.
I just want to extract date alone because in date_order it is given date with date time. how to work with it ?
here is my code :
from_date = fields.Date(string="From", default="Today")
to_date = fields.Date(string="To")
def update_commission(self):
sale_br = self.env['sale.order']
sale_sr = sale_br.search([('date_order', '=', self.from_date)])
Modify your function like this:
def update_commission(self):
sale_br = self.env['sale.order']
sale_sr = sale_br.search([]).filtered(lambda sale: sale.date_order.date < self.from_date)
If you are working in odoo's past version like 10,11 than you need to convert this datetime into datetime object because when you call this field it will return date in string format so you need to do fields.Datetime.from_string(sale.date_order.date)
Hello i am quite new to ruby on rails so please be easy on me. I have a rails app which consist of a table displaying record. I have a search bar which filters the result of the table by date. My search bar select tag looks like this
select_tag :date, options_for_select(#previous_summary_history_dates.uniq), prompt: "Search by date", id: "summary-history-date-filter", class: "form-control"
This is my #previous_summary_history_dates in the controller from where the select tag gets the value from
#previous_summary_history_dates = SummarySheet.where(is_history: nil).pluck(:record_inserted_at).map{|a| a.strftime("%m/%d/%Y - %l:%M %p")}.uniq
I have set the application.rb file to this
config.time_zone = 'Pacific Time (US & Canada)'
config.active_record.default_timezone = :local
I have a query for the search bar, which display the record in the table filtered by date selected from the select tag, which is something like this
#summary_history = SummarySheet.where(record_inserted_at: DateTime.strptime(params[:date], "%m/%d/%Y - %l:%M %p").at_beginning_of_minute..DateTime.strptime(params[:date], "%m/%d/%Y - %l:%M %p").at_end_of_minute)
This query works but it gives me the output in UTC format which doesnt match with my PCT format of the select tag and i get result as null. If i change my select tag time zone to UTC i get the desired output.
i tried .in_time_zone("Pacific Time (US & Canada)") in my filter query to convert the date in PCT but that didnt work
Can some one please suggest me how can i keep the select tage in PCT and fire the query and still get the dates filtered output? Thanks in advance
I solved it by changing the query to
#summary_history = SummarySheet.where(record_inserted_at: Time.zone.strptime(params[:date], "%m/%d/%Y - %l:%M %p").at_beginning_of_minute..Time.zone.strptime(params[:date], "%m/%d/%Y - %l:%M %p").at_end_of_minute)
CREATE PROCEDURE sp_ME
#ID int,
#ThisDate datetime = null
AS
SET NOCOUNT ON
IF #ThisDate IS NULL
BEGIN
SET #ThisDate = CURRENT_TIMESTAMP
END
DECLARE #intErrorCode int,
#QBegin datetime,
#QEnd datetime
SELECT #intErrorCode = ##ERROR
IF #ThisDate BETWEEN '01/01/' + CONVERT(VARCHAR(4), YEAR(#ThisDate))
AND '03/31/' + CONVERT(VARCHAR(4), YEAR(#ThisDate))
BEGIN
Select #QBegin = DATEADD(s,0,CAST ('10/01/' AS varchar(6) ) +
CONVERT(VARCHAR(4),DATEPART (year,#ThisDate)-1))
Select #QEnd = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,#QBegin)+3,0))
SELECT * FROM QUERY
WHERE MEID = #ID
AND mydate >= #QBegin
AND mydate <= #QEnd)
END
SELECT #intErrorCode = ##ERROR
IF (#intErrorCode <> 0) GOTO ErrHandler
ErrHandler:
RETURN #intErrorCode
GO
It returns a dataset when you leave it blank and it assumes and fills in the date, however when you plug in a date it just states "The command completed successfully."
Any help would be more than appreciated.
At a guess, you need to query the previous quarter's results, which would just be this query:
SELECT * FROM QUERY
WHERE MEID = #ID
AND mydate >= DATEADD(quarter,DATEDIFF(quarter,'20010101',#ThisDate),'20001001'),
AND mydate < DATEADD(quarter,DATEDIFF(quarter,'20010101',#ThisDate),'20010101'))
And get rid of that big if condition, etc.
You could also get rid of the first if, if you put COALESCE(#ThisDate,CURRENT_TIMESTAMP) in the above, where I currently have #ThisDate.
I use the DATEADD(quarter,DATEDIFF(quarter,'20010101',#ThisDate),'20001001') pattern for a lot of datetime manipulation. It let's you achieve a lot in a few operations. In this case, it's the difference between the two dates ('20010101','20001001') which is giving us the previous quarter.
You'll frequently encounter the DATEADD/DATEDIFF pattern in questions involving removing the time portion from a datetime value. The canonical version of this is DATEADD(day,DATEDIFF(day,0,#Date),0). But the pattern can be generally extended to work with any of the datetime components. If you choose month rather than day, you'll get midnight at the start of the first of the month (of the day you've supplied)
Where it gets tricky is when you use dates (instead of 0), and especially if you don't use the same date for both calculations. This allows you to apply an additional offset that seems almost "free" - you're already using this construct to remove the time component, the fact that you can compute e.g. the last date in a quarter/month/etc is a bonus.