SQLite Group by Month - sqlite

I am using SQLite Database and in one my table has field purchased_date (TEXT ,since DATE is not in SQLLite)
Now I want to run query that return me all the results where user purchased in Month of February 2012
I am storing Dates in following format
Tue Mar 27 09:38:31 BST 2012
Is it possible to run query for above date format or do I need to put in different format ?

You can use the strftime built-in function to extract the month from the stored text value and group by this.
A full list of the datetime functions can be found here http://sqlite.org/lang_datefunc.html

Related

How to convert a specific date format into a proper data type and query related records between dates?

I am learning neo4j and have a problem where a given data set I have uploaded has a weird date format which I can't query using neo4j's bult in date functions because it was uploaded as a string. The format is the following:
╒══════════════════════════╕
│"t.date" │
╞══════════════════════════╡
│"Mon 18 Feb 2019 12:18:57"│
├──────────────────────────┤
│"Mon 18 Feb 2019 12:18:57"│
└──────────────────────────┘
I have already created a node that contains date as a property and stores the dates in the above format.
How can I change this so I can query the associated node to return results BETWEEN certain dates, so for example:
MATCH (t:Text)
WHERE t.date = 'Mon 18 Feb 2019 12:18:57'
RETURN t.description;
I would need to be able to query for Texts in between certain dates for example texts written in between Mon 18 Feb 2019 12:18:57 and Mon 19 Feb 2019 12:18:57
Thank you!
There are two ways:
Change the existing date property to Neo4j 'DateTime'. Which can be easily queried. (RECOMMENDED)
Keep the date property as it is and use apoc to compare the date each time you want to query. (NOT RECOMMENDED)
You can use apoc.date.parse function from APOC Plugin to parse the date string into epoch time by specifying the SimpleDateFormat
You can use the following query to change your existing dates into Neo4j 'DateTime': (For Solution 1)
MATCH (n:Text)
WHERE n.date IS NOT NULL
SET n.date=datetime({epochmillis:apoc.date.parse(n.date, 'ms',"EEE dd MMM yyyy HH:mm:ss")})
Refer Neo4j DateTime
Note: Install APOC before running above query.
Once you convert the date string into datetime format, you can do below query to get text description when date is between Feb 18 and 19 12:18:57. Notice the letter 'T' at the middle. It means time.
MATCH (t:Text)
WHERE t.date > datetime('2019-02-18T12:18:57')
AND t.date < datetime('2019-02-19T12:18:57')
RETURN t.description;
Reference:
https://neo4j.com/docs/cypher-manual/current/functions/temporal/datetime/#functions-datetime-create-string

Hive Date Time Week

I want to extract date of each week's Monday for each week in hive. I can do that with Presto by using date_trunc function however in hive I don't have a direct function which can extract Monday Date.
My Presto code is similar to this,
select
a.abc_id
,cast(date_trunc('week', from_unixtime(p.xyz_date)) as timestamp) as xyz_week
from PQR
The output is for each id I will get Week but in the form of date format which is nothing but the date of every Monday of past weeks (user can specify how many week's he wants to assess).
I searched all the date functions of hive but is there a function which can replace date_trunc?
what you need is the date function : next_day(string start_date, string day_of_week)
For example: next_day('2018-02-22', 'Mon') = '2018-02-26''
My hive version is 1.4.

Identifying what date this value represents in SQLite

I am brand new (!) to SQLite and will not be studying or using it long-term; however, I am trying to paw through a bit of archived data in a sqlite database using db browser for sqlite.
There is a table with a date field with a value like this: 1435610912000000
Does that make any sense to anyone as to a date of some kind ??
That is the number of microseconds from 1970 (epoch). Therefore, that is 1435610912000 milliseconds (or 1435610912 seconds), which converts to Mon Jun 29 2015 20:48:32 UTC using this website.
This can be a timestamp which every programming language has a function for converting it to a Date objec.
var date = new Date(1435610912000000);
This code above is Javascript that casts the number 1435610912000000 to date
Sat Sep 13 47462 01:53:20 GMT+0100 (WAT)
which is a bit off but the best guess is that it is a timestamp

SQLite timestamp conversion function

I've inherited a SQLite DB, in it I've a TIMESTAMP field called ZDATE.
One value is 401,580,000 and I know it correspond to Sept 23rd, 2013.
I've calculated that the 0 of this field is the midnight of Jan 1st, 2001 (?).
However, I didn't find any conversion function to get a formatted date, in fact if I use date() I get:
ZDATE date(zdate)
401580000 1094776-12632211-20
Any help will be appreciated.
> select 401580000 / (julianday('2013-09-23') - julianday('2001-01-01'));
86398.4509466437
> select 60*60*24;
86400
So this timestamp appears to use seconds.
To convert it into a timestamp that SQLite can use directly, i.e., a Unix epoch timestamp, just add the appropriate offset:
> select datetime(401580000 + strftime('%s', '2001-01-01 02:00:00'), 'unixepoch');
2013-09-23 00:00:00

SQL Developer: Load Data Date error

I am using Oracle SQL Developer 3.0.03. I am trying to upload an Excel file to an Oracle data table. I am getting an error for the date. The column in the database is a timestamp and I don't know what to put into the date format for the 'Data Load Wizard'. If I use the following format (dd-mom-yy hh.mi.ss), SQL Developer will show the following error:
--Insert failed for row 1 TIMESTAMP_COLUMN GDK-05047: A day of the month must be between 1 and the last day of the month.
--Row 1
INSERT INTO TABLE_1 (Column1, Column2, Column3, TIMESTAMP_COLUMN) VALUES ('Some Text','Some Text','Some more text',to_timestamp('40604.0', 'dd-mon-yy hh.mi.ss'));
The default number format IN EXCEL is: 40604.0
Which if you change the cell to a short date format you will get: 3/2/2011
I am trying to figure out what 'Format' I need to put into the FORMAT section of the 'DATA Load Wizard' that will accept the date format that is in EXCEL and upload it to Oracle as a TIMESTAMP.
I ran into the same thing today, and 'fixed' this two ways. The second way probably seems too complex, but it might help someone if they have a hard time automating the formatting of dates to look like Oracle's standard dd-mmm-yy.
Format the date columns in Excel as dd-mmm-yy and import directly into the table.
Highlight the column(s)
Choose "More Number Formats" where the existing format is (In Excel 2010, it says General in a dropbox on the Home tab
Select the last entry "Custom" in the Category box
Manually enter dd-mmm-yy in the Type: box
Format the date columns in Excel as mm/dd/yy, import the table in as text, write a manual insert statement from the temp text table using TO_DATE(date_field,'MM/DD/YYYY')
Highlight the column(s)
Choose "More Number Formats" where the existing format is (In Excel 2010, it says General in a dropbox on the Home tab
Select the "Date" entry in the Category box
Choose "03/14/01" from the list
The Excel "zero" date is January 0 (yes, zero), 1900. Since Oracle can't handle a "zero" day in a month you need to subtract 1 from the Excel value; thus the following should get you close to what you want:
SELECT CAST(TO_DATE('01-JAN-1900 00:00:00', 'DD-MON-YYYY HH24:MI:SS') AS TIMESTAMP) +
NUMTODSINTERVAL(41017.6361109954 - 1, 'DAY')
FROM DUAL
As far as "how to import it" goes, there's no Oracle date format that I'm aware of to do this. The easiest thing would be to import the value into a NUMBER column and then run a script to do the date conversion.
Share and enjoy.
yeah and that's the problem.
"A day of the month must be between 1 and the last day of the month."
1) how are these decimals created?
2) is this "04-06-2004" ? or are these seconds from 1970?
you need to add more detail about this number format!

Resources