I have a select query that returns records based on 2 dates from a form - >=Forms!frmReport!StartDate AND <=Forms!frmReport!EndDate.
The problem is that whenever the user enters the same date in the both StartDate and EndDate no record is returned even though I'm sure there is data in the table that matches the criteria. Can anyone say why the query isn't returning any information?
Cast the form values to just date values in your query:
>= cdate(Forms![frmReport]![StartDate]) and <= cdate(Forms![frmReport]![EndDate])
And set your field default to =date() to capture the date only, instead of =now().
If the field being compared is rs("Date"), try
Int(rs("Date")) >=Forms!frmReport!StartDate AND Int(rs("Date")) <=Forms!frmReport!EndDate
For the Query Builder, modify your date checking field to something like this:
Replace YourDateField with the name of your field.
And if time is relevant, get rid of the field expression in the query builder, and instead compare the record's field to:
>=Forms!frmReport!StartDate AND <= iif(Forms!frmReport!EndDate = Forms!frmReport!StartDate, dateadd("d",1,Forms!frmReport!EndDate), Forms!frmReport!EndDate)
This expression says if the end date is the same as the start date add a day, otherwise just use the end date.
Related
I am trying to pull the value from the 'dwgm_10am_final_price' column with today's current date (2021-01-06). In this case it will be null until a value is inserted into the table at 10am. as depicted in the image below.
This is the current query I am trying but it is returning 'No Data' on my Grafana dashboard. How can I edit my query to always pull the data with today's timestamp, regardless of it is NULL or a numerical value.
SELECT gas_date AS time, dwgm_10am_final_price
FROM gas_market_prices
WHERE DATE('time') = CURDATE()
You are trying to get a date from the String time, which doesn't exist
You need to use backticks for your query
SELECT gas_date AS time, dwgm_10am_final_price
FROM gas_market_prices
WHERE DATE(`time`) = CURDATE()
You can read this canonical thread When to use single quotes, double quotes, and backticks in MySQL
i have a MySQL's db with 2 DATE columns and when i add a registry the date is saved like this 2018/07/30. The problem is that when i make a get call to the db the value comes like this"2018-07-30T03:00:00.000Z"
I do not need the time part, and i think that the DATE type i have set to the column should not return this kind of value.
I have tried this but it does not work:
"SELECT * FROM patrones WHERE DATE_FORMAT(bd_fRecepcion, '%Y-%m-%d') WHERE bd_SI = 'Si' "
How could i do to get retuned the date part only?
Thanks for your help.
i have an events table having start date and end date I am trying retrieve all the records by giving a date that is between start and end dates.
eg :
SELECT *
FROM `events`
WHERE '2017-01-29' BETWEEN start_date='2017-01-28'
AND end_date='2017-01-31'
but response is syntax error can any one help me to finish the query
Just list the columns.
WHERE '2017-01-29' BETWEEN start_date AND end_date
The values come from the table, you don't put them into the query.
According to mysql documentation (https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_between) the syntax for BETWEN is
expr BETWEEN min AND max
it is not
expr BETWEEN blabla=min AND stuff=max
Also, it is rather pointless to be using constants in all three expressions, because in this case the result will be known in advance (either always TRUE or always FALSE) without having to consult the values in your table.
It is kind of hard to give you an example without knowing the structure of your table, but what you probably want is something like
WHERE '2017-01-29' BETWEEN start_date
AND end_date
(assuming start_date and end_date are columns in your table)
or something like
WHERE some_column BETWEEN '2017-01-28'
AND '2017-01-31'
(assuming some_column is a column in your table.)
I believe you're trying to find all the rows where a date is 2017-01-29, and so, your query could be:
SELECT *
FROM `events`
WHERE
date = '2017-01-29';
If, however, you want all rows with date between 2017-01-28 and 2017-01-31, then you could do:
SELECT *
FROM `events`
WHERE
date BETWEEN '2017-01-28' AND '2017-01-31';
Instead of putting 2017-01-29 before WHERE, put the name of the field you want to filter by date, such as EventDate (or whatever your field is named).
I am using DLAST to return a specific field value for the last record. The issue I am having is that the last record isn't always the newest date record. I need to return the value of a specific field for the newest date record.
You can't depend on DLast() to return a value from the "last record" of a table unless you use a query based on the table and indicate how the rows should be ordered. From the Application.DLast Method help topic ...
NoteIf you want to return the first or last record in a set of records (a domain), you should create a query sorted as either
ascending or descending and set the TopValues property to 1.
If you want to use DLast(), create a query and use the query name as the domain argument. For example, with this as Query1 ...
SELECT ASSY
FROM L2_AOI1
ORDER BY [your date field];
... this should work as the text box's Control Source ...
=DLast("ASSY", "Query1")
However, you could use a different query which returns the most recent ASSY and use DLookup with that query. For example, with Query2 ...
SELECT TOP 1 ASSY
FROM L2_AOI1
ORDER BY [your date field] DESC;
=DLookup("ASSY", "Query2")
Either way, include an index on [your date field] to optimize performance.
You can also use DLookup directly with an SQL clause:
=DLookup("Assy", "L2_AOI1", "[YourDateField] = (Select Max([YourDateField]) From L2_AOI1)")
I am working for a POS company, i have a query in my program that gets date from multiple tables and one of the fields it returns is a date field that returns the the date in the format yyyy-mm-dd. Is there a way to get my query to bring this date field in the form 'dd'? if yes how?
You are looking for the date_format() function (see here):
select date_format(<datefield>, '%d');
This returns the value as a string. If you want it as a number, just use day():
select day(<datefield>)
You are looking for this:-
EXTRACT(unit FROM date)
or try this:-
SELECT DAY(your_date_field) AS dtDay FROM your_table
select DATE_FORMAT(your_date_column,' %d ') FROM your_table
As you mentioned Delphi, why not a Delphi solution:
open the query in a dataset
get the corresponding field
get the value with AsDateTime
use function DayOf from System.DateUtils to retreive the day
in case you need a dataset field for that, create a calulated field
move the day calculation into the OnCalcFields event of the dataset
There might still be plenty of other ways to do it.