Identifying what date this value represents in SQLite - 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

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

How to convert a String into an Ecto.DateTime in Elixir?

I need to convert a string containing a valid UTC time to an Ecto.DateTime one, which I will insert it into my database with the correct format later. I have tried using the Ecto.DateTime.cast(date) method but it doesn't seem to work. The string is Sat Aug 04 11:48:27 +0000 2012 and comes from the Twitter API.
I know there are libraries such as Timex which I didn't inspect yet. Is there any easy working solution already built in Elixir?
There's no built-in solution in Elixir or Erlang for parsing DateTime values of this format:
Sat Aug 04 11:48:27 +0000 2012
You can certainly write a parser yourself, but it's neither going to be short or simple. You'll have to split the string, get the values of both date and time parameters, convert month strings to month integers, parse the timezone, represent the complete value in Elixir/Erlang DateTime formats and then finally cast it to Ecto.DateTime. See the following links:
Elixir Tips - Date Parsing
Erlang - How Can I Parse RFC1123 Dates Into An Erlang Term?
Convert timestamp to datetime in erlang
Using Timex is the best option here.
It's a well written library that allows you to stay away from the chaos of inner workings of Date/Time. With Timex, you can parse your string like this:
"Sat Aug 04 11:48:27 +0000 2012"
|> Timex.parse!("%a %b %d %T %z %Y", :strftime)
|> Ecto.DateTime.cast!
# => #Ecto.DateTime<2012-08-04 11:48:27>
Note: Timex has built-in support for a lot of the common DateTime formats, and I found it weird that a DateTime format being sent by Twitter wasn't supported - so I wrote one for you. Maybe double check to see if your string is correct? Also take a look at Timex Parsing and Formatting documentation.

Decoding flight Arrival / Departure time format

I've been using a real time flight traffic API lately and I'm stuck at formating the arrival / departure times from a json response.
They come like this:
{
"dep_schd":1426843500,
"arr_schd":1426849800,
"departure":1426844020,
"arrival":1426849221
}
It doesn't look like anything I've seen before. Any ideas on how to make these times readable?
As a bonus, I can give you how an estimated time arrival looks like:
"eta":1426849221
Thank you
Edit:
Okay guys, with a bit more research and the help from you guys I managed to convert my date to a human readable date like this:
var departure = $('#departure');
var departureDate = new Date(json.departure * 1000);
departure.html(departureDate.toUTCString());
Now what I get is something like this:
Fri, 20 Mar 2015 09:33:40 GMT
My question is how can I make it simpler? So as I can get something like this:
Fri, 20 Mar 2015 09:33
This is Unix time. The number of seconds since 01 Jan 1970, 00:00:00 UTC.
On Unix you can use functions like localtime or gmtime and strftime to convert it to a human-readable form. Most languages have similar functions for dealing with these unix timestamps.
To display it in another format, use the "get" functions on the Date object (since it looks like this is JavaScript). For example departure.getUTCHours().
A better solution though is to use a library like moment.js to format the date easily:
var mDeparture = new moment(departureDate);
departure.html(mDeparture.format('YYYY-mm-dd'));
The format which your are displaying is called Epoch and it is then converted into human readable format.Here is a online site where u can get this in readable format http://www.epochconverter.com/
But you didn't mention in which language you want to convert , every language as methods to convert this in human readable and then you have to pick which info you want from it.

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

SQLite Group by Month

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

Resources