Using a query with a datetime cell in spreadsheets - datetime

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

Related

SQLite Epoch time query

Could use a bit of help on this. I have a table which stores records in JSON format in the acctinfo column. I can export the JSON content without issues, but the problem i'm running into is with the epoch time. I would like to be able to display my LastLoginTime in standard locatime format(Not convert the column, but rather convert the output to make it understandable). Any suggestion would be greatly appreciated.
SELECT name,
json_extract(table1.acctinfo, '$.LastloginTime'(1319017136629, 'unixepoch', 'localtime'))
from table1;
Here's an example of the JSON stored in the acctinfo column:
{
"AcctCreateTime": 1518112456,
"LastLoginTime": 1601055231,
"LastModified": 1518112456,
}
Use the function datetime() and json_extract() like this:
SELECT datetime(json_extract(acctinfo, '$.LastLoginTime'), 'unixepoch', 'localtime')
FROM table1;
See a simplified demo.

Date parameter mis-read in Delphi SQLite Query

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.

SQLite3 DateTime comparison in linux

As per seen in image my first query return 5 rows but my second query does not return any rows.
It shoud be return 3 rows.
I also have tried with
Store my all datetime data in format of 'yyyy-MM-dd hh:mm:ss'
"SELECT billheaderid,billheadercode,billtotalitem,billtotalamount,createdby,createdon WHERE cretedon >= Datetime('2014-08-19 12:26:32')"
Date values with "AM/PM" fields cannot be compared correctly with string comparisons
(1 is larger than 0).
You have to change all the values in the database to the correct format yyyy-MM-dd hh:mm:ss.
(And it is not necessary to call the datetime function.)
Store your data in form of
'yyyy-MM-dd hh:mm:ss'
And please care that '2014-08-19 03:45 PM' must be store as '2014-08-19 15:45:23' not as '2014-08-19 03:45:23'.
After that you don't need use datetime function. I am sure it'll work 100%.

SQLite Extract Month From Column

I have a column of data with this date format mm/dd/yyyy. I would like to covert to this to the format yyyy-mm-dd for (SQLite usage). How could I achieve this?
UPDATE Table_Name
SET Column_Name = 'yyyy-mm-dd' format
I have tried substr, ltrim, rtrim (None of this work for my case).
My data are dynamic.
Sample
Column_Name
6/1/2004
06/25/2004
7/1/2003
6/1/2004
6/1/2004
09/19/2003
09/30/2003
09/30/2003
09/30/2003
09/30/2003
The Goal: Extract only month from this Column (Without displaying unnecessary stuff)
Thank you.
The syntax for extracting a specific date element from a date field is to use strftime.
SELECT strftime('%m', Column_Name) AS month which is your second question. For reconstituting the date data you could use (at least in JavaScript) substr to split the date out then format it as you require. Also see this post:Get month from DATETIME in sqlite

SELECT clause with a DATETIME column in Sybase 15

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.

Resources