I am struggling to select specific month with SQLite.
SELECT *
FROM order
WHERE strftime('%m', transaction_date) = '10';
I have tried this and it shows "[21:55:30] Query finished in 0.000 second(s)." but nothing showed up in Grid View. This is what I have in order table. I have tried changing the date to 10-23-2015 format as well but it didn't work. I don't want to use LIKE because these is an assumption that I can't see the date format.
Dates are stored as text in SQLite, so you can just use substring here:
SELECT *
FROM order
WHERE SUBSTR(transaction_date, 1, 2) = '10';
Related
I need to query a cell that contains a datetime but its formatted by default when I import it to only show the date.
31/7/2020 19:18:58 (in reality it's like this)
31/7/2020 (but it shows this)
So when I run this query:
=QUERY(A5:R10, "select K")
It returns only the date no matter what I do:
31/07/2020
I've tried:
Options
Formatted like "yyyy-MM-dd HH:mm" it returns 00:00
Filter by datetime or timestamp
Used '"&Text(now(), "yyyy-mm-dd HH:mm"&"' or something like that
The question is:
Is there a way to do what I'm trying to do without reformatting the imported cells?
link to test it:
https://docs.google.com/spreadsheets/d/14rGPngGvFXGP8txMS2yFo1v4gPcI4K1oYWj_8yt2Uq8/edit?usp=sharing
when I select one cell with F2 it shows the time:
Thanks a lot for your time!
select column B and format it as date time
or without reformating it:
=ARRAYFORMULA(QUERY(1*(B2:B4&""), "format Col1 'yyyy-mm-dd hh:mm:ss'"))
or:
=ARRAYFORMULA(QUERY(TEXT(B2:B4, "yyy-mm-dd hh:mm:ss"), "select *"))
Just make sure your cells are formatted as Automatic
If not, even if you use the format clause of the query, the clause will be ignored
What is wrong with my code:
ExecSql('DELETE FROM STLac WHERE RegN=99 AND BegDate>= 2016-12-14');
This runs, but deletes ALL the rows in STLac for RegN, not just the rows with BegDate on or after 2016-12-14.
Originally I had:
ExecSql('DELETE FROM STLac WHERE RegN=99 AND BegDate>= :myDdate,[myDate]);
which has the advantage I hoped of not being particular to the date format. So I tried the literal date should in the format SQLite likes. Either way I get all rows deleted, not just those on or after the specified date.
Scott S.
Try double quote while putting date. As any value must be provided in between quotes until and unless that column is not int
ExecSql('DELETE FROM STLac WHERE RegN=99 AND BegDate>= "2016-12-14"');
SQLite does not have datetime format as such, so you have to figure out how date is actually represented in the table and change your query to provide the same format. First execute the "select" statement in some kind of management tool,
select * from STLac where RegN = 99 and BegDate >= '2016-12-14' --(or '2016.12.04' or something else)
which displays the result in the grid; when you see the expected rows, change it to "delete" query and copy into your Delphi program.
I have an sqlite table with with 2 date columns (beginning & end). I am looking for a query that returns the date range a date falls in. e.g Checking range where 10-02-2016 falls given 2 records as follows
(01-02-2016 - 12-02-2016) & (13-02-2016 - 20-02-2016)
Clearly it falls in the first range but how do I do it in SQLITE. Please help?
I think the problem is next SQLite requires dates to be in format YYYY-MM-DD. With that format you could write a simple query:
select * from table where yourdate between begin and end
If you can't change your format you should look at next sqlite functions https://sqlite.org/lang_datefunc.html
Also you can try substr function to cotact date in needed format.
I have a database table containing a row of dates in DateTime format. what I need to do is get all the distinct weeks numbers of the available dates. for example if I have the following dates:
03-JAN-13
04-JAN-13
09-JAN-13
the sql query would give me the following weeks numbers: 1 and 2.
PS: afterwards I will put these values in a dropdownlist (no problem with that step).
So can anybody tell me how to do it?
You did not specify what RDBMS you are using but you could use the following to get week numbers.
SQL Server you would use DatePart():
select distinct datepart(week, dates) WeekNo
from yourtable
See SQL Fiddle with Demo
In MySQL you could use Week():
select distinct week(dates)
from yourtable
See SQL Fiddle with Demo
In Oracle, you could use to_char():
select distinct to_char(dates, 'W') WeekNo
from yourtable
See SQL Fiddle with Demo
In PostgreSQL you can use the following:
select distinct extract(WEEK from dates) WeekNO
from yourtable
See SQL Fiddle with Demo
Replace the yourtable with your table name and dates with your date column.
Edit #1: If you are using MS Access then you can still use DatePart() (this was tested in MS Access 2003):
SELECT distinct datepart("ww", dates) as WeekNo
FROM yourtable;
In your on load event, or wherever you want, you will put this VBA code
Me!myCombo.RowSource = "yourquerytexthere;"
(Or whatever query you go with..probably whichever one you're using from your last question that Remou answered for you).
I think in this question, you already know what you want to query, you are just asking about setting the control.
That code is just
Me!myCombo.RowSource = "yourquerystring"
like
Me!myCombo.RowSource = "SELECT distinct datepart("ww", dates) FROM yourtable;"
Where Me!myCombo is the name of your combobox.
Annual ISO week# table - Oracle SQL query:
-- ISO_WK# --
SELECT mydate
, TRUNC(mydate, 'w') wk_starts
, TRUNC(mydate, 'w') + 7 - 1/86400 wk_ends
, TO_NUMBER (TO_CHAR (mydate, 'IW')) ISO_WK#
FROM
(
SELECT TRUNC(SYSDATE, 'YEAR')-1 + LEVEL AS mydate
FROM dual
CONNECT BY LEVEL <=
(-- First day of curr year - first day of past year --
SELECT TRUNC(SYSDATE, 'YEAR')-TRUNC(ADD_MONTHS (SYSDATE, -12), 'YEAR') "Num of Days"
FROM dual
)
)
/
I'm trying to do a query like this on a table with a DATETIME column.
SELECT * FROM table WHERE the_date =
2011-03-06T15:53:34.890-05:00
I have the following as an string input from an external source:
2011-03-06T15:53:34.890-05:00
I need to perform a query on my database table and extract the row which contains this same date. In my database it gets stored as a DATETIME and looks like the following:
2011-03-06 15:53:34.89
I can probably manipulate the outside input slightly ( like strip off the -5:00 ). But I can't figure out how to do a simple select with the datetime column.
I found the convert function, and style 123 seems to match my needs but I can't get it to work. Here is the link to reference about style 123
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.blocks/html/blocks/blocks125.htm
I think that convert's slightly wrongly documented in that version of the docs.
Because this format always has century I think you only need use 23. Normally the 100 range for convert adds the century to the year format.
That format only goes down to seconds what's more.
If you want more you'll need to past together 2 x converts. That is, past a ymd part onto a convert(varchar, datetime-column, 14) and compare with your trimmed string. milliseconds comparison is likely to be a problem depending on where you got your big time string though because the Sybase binary stored form has a granularity of 300ms I think, so if your source string is from somewhere else it's not likely to compare. In other words - strip the milliseconds and compare as strings.
So maybe:
SELECT * FROM table WHERE convert(varchar,the_date,23) =
'2011-03-06T15:53:34'
But the convert on the column would prevent the use of an index, if that's a problem.
If you compare as datetimes then the convert is on the rhs - but you have to know what your milliseconds are in the_date. Then an index can be used.