I was writing an application on c#, which is save DateTime to the Text field in the database.
Format of date is:
'1/15/2020 14:48:44', '2/11/2020 12:53:59' and etc
Now I want to get records with SQL query by the last few days.
I understand that I need convert text to date, and compare. But SQL query return 0 results. My query is:
select * from LogRootProcessing where strftime(dateparsing) < strftime('%MM/%DD/%YYYY %HH:%MM:%SS','2/11/2020 12:53:59')
Could you please advise how to fix the query?
Thanks in advance.
Related
We receive a string '2019-11-30T18:00:00GMT-06:00' in the JSON file and this need to be converted to timestamp to load into the timestamp column in the snowflake. I tried multiple options convert_timezone,to_timestamp etc, however in vain, Can you please let me know how i represent this string (2019-11-30T18:00:00GMT-06:00) in data format for comversion.
Thanks !
Leveraging a more Snowflake way to do this, you'd want to run something like this:
SELECT TO_TIMESTAMP('2019-11-30T18:00:00GMT-06:00','YYYY-MM-DDTHH:MI:SSGMT-TZH:TZM');
The output of this will be the date/time of your account default along with the timezone offset that goes along with that.
Please try the below mentioned approach
if your table is create as below
CREATE TABLE TIMESTAMP_TEST(DATE TIMESTAMP);
Insert the value as
INSERT INTO TIMESTAMP_TEST SELECT REPLACE(REPLACE('2019-11-30T18:00:00GMT-06:00','GMT'),'T',' ') FROM DUAL
Thanks
I am using SQLite.
In my database, I have a integer column value like 20050819. I would like to convert this as date column as like 2005-08-19.
I can achieve my requirement when using the function CONVERT(columnName, DATETIME) in MySQL server. But I need the same result in SQLite.
Is this possible in SQLite query?
You basically have to break apart the date:
select printf('%4d-%02.2d-%02.2d',
columnname/10000, columnname%10000/100, columnname%100)
from tablename;
P.S.
If you have the choice, you will be far better off storing the date in ISO standard format ('YYYY-MM-DD') in the database in the first place.
I have a number of "DATETIME's" for the following form e.x.:
2014-01-15T19:30:00-0800
I am successfully inserting them into an sqlite table that I created with the following statement:
CREATE TABLE STUFF(id unique,date_time DATETIME)
When I query using the statement below I get all the dates I inserted back but not ordered.
SELECT * FROM STUFF ORDER BY DATETIME(date_time) DESC;
I'm guessing this is a formatting issue but I'm not sure. Can anyone spot what I'm doing wrong?
This is not a date format supported by SQLite;
a time zone indicator must have the form ±HH:MM:
> SELECT DATETIME('2014-01-15T19:30:00-0800');
> SELECT DATETIME('2014-01-15T19:30:00-08:00');
2014-01-16 03:30:00
I am currently stuck with a database issue where I need to manipulate data using my database inserts. I am currently doing a website with C# ASP.NET on Visual studio 2012 and the database I am using is SQL Management 2008.
Firstly, I currently store my System.Date into a string and store it as a nvarchar datatype in my database. If I would like to perhaps get the latest 10 rows from for example, user= 'x', how should I actually go about doing the SELECT statement to only get the data I specified?
And I currently store information like Date Of Birth using the calander Ajax toolkit so the format the dates are saved in is in month/day/year format. The data is stored into my database as a nvarchar as well. If I want to perhaps calculate the age of user='x' how should I calculate it?
I think Jon's comment about storing the data properly as a datetime is spot on:
Why are you storing it as an nvarchar to start with? It's logically a
date/time, not a string - so store it as a date/time. Get rid of the
string part, and all your formatting problems go away too.
Definitely do that if you can.
If, for some reason, you can't change your database structure, you can use a CAST / CONVERT statement in your ORDER BY clause to get what you want:
SELECT TOP 10 *, CAST(yourDateField AS datetime) AS convertedDate
FROM yourTable
WHERE
user='Some user'
ORDER BY CAST(yourDateField AS datetime) DESC
This assumes that your nvarchar data can be properly converted to a datetime (which it should be if you're using the Ajax Control Toolkit calendar extender).
Hiii Freinds
I have an serious issue in android.I am using SQlite as my DB. In my application i am storing date as text field as sqlite don't have date datatype.In the report section i am taking from and to date from user fetching records from sqlite as below,
select * from Table2 where TDate >= '2013-1-1' and TDate <='2013-3-1'
The problem is that above query runs correct ,but when I use date with month higher than 10 eg.'2013-10-1' or '2013-11-1' or '2013-12-1' it was not fetching any records please help
Thankx In adv.
You must use one of the supported date formats such as yyyy-mm-dd so that the string comparison come out right.
(In a string, 1 < 9, therefore 10 < 9.)