SQL Lite - Timestamp - iphone

I've downloaded some iPhone databases and I wonder what the "Timestamp" column does exactly:
411024581.457056 --> how can I get this as readable Date string with time stamp? (dd-MM-yyyy HH:mm:ss)
SELECT strftime('%d - %m - %Y ', datetime(Timestamp, 'unixepoch')), Latitude, Longitude FROM CellLocation
This gives me 10-01-1983 which cannot be ok.
I've found that query in another question:
Thanks.

As outlined in this blogpost (referring to the Apple Documentation), the date in such timestamp columns is formatted like with the unixepoch type, however, while unixepoch asummes January 1, 1970, as its point of origin, Apple uses January 1, 2001.
Therefore, you will need to add the unix timestamp that matches the difference between the two points of origin to the values before converting the result to a readable datetime value - as indicated by the aforementioned blogpost:
datetime(ZONLINEDATE + 978307200, 'unixepoch', 'localtime')

Related

Converting DateTime to Epoch milliseconds using Cypher in Neo4J

I'm running a query using Cypher in Neo4J where I have to compare a createdAt property of a node against a given time unit in Epoch milliseconds. This createdAt property is a string in the DateTime format, which is defined as -
DateTime
date with a precision of miliseconds, encoded as a string with the following format: yyyy-mm-ddTHH:MM:ss.sss+0000, where yyyy is
a four-digit integer representing the year, the year, mm is a
two-digit integer representing the month and dd is a two-digit integer
representing the day, HH is a two-digit integer representing the hour,
MM is a two digit integer representing the minute and ss.sss is a five
digit fixed point real number representing the seconds up to
milisecond precision. Finally, the +0000 of the end represents the
timezone, which in this case is always GMT.
Here are a couple of values of this property - 2011-03-21T19:32:38.295+0000, 2012-03-09T17:59:05.367+0000.
I came across the Temporal Values documentation on Neo4j, but couldn't find a way to perform the conversion.
When I execute some of the given examples, like this -
RETURN datetime('2015-06-24T12:50:35.556+0100') AS theDateTime
I get the error -
Neo.ClientError.Statement.SyntaxError: Unknown function 'datetime' (line 1, column 16 (offset: 15))
Would appreciate any help!
The temporal functions were added in neo4j version 3.4.0, and I have verified that your query works in that version.
Make sure you are using an appropriately recent version of neo4j.

BigQuery upload date error from csv file

I have been trying to upload a table with dates on the from a csv file but I keep getting an error about the date type like this:
Errors:
Too many errors encountered. (error code: invalid)
query: Invalid date: '2010-06-31' (error code: invalidQuery)
So it is complaining about 2010-06-31. I checked the reference and it says:
Date type
Name Description DATE Represents a logical calendar date. Values range
between the years 1 and 9999, inclusive. The DATE type represents a
logical calendar date, independent of time zone. A DATE value does not
represent a specific 24-hour time period. Rather, a given DATE value
represents a different 24-hour period when interpreted in different
time zones, and may represent a shorter or longer day during Daylight
Savings Time transitions. To represent an absolute point in time, use
a timestamp.
Canonical format
'YYYY-[M]M-[D]D' YYYY: Four-digit year [M]M: One or two digit month
[D]D: One or two digit day
https://cloud.google.com/bigquery/sql-reference/data-types#date-type
It says YYYY-[M]M-[D]D so I thought 2010-06-31 is correct but still getting an error.
My rows look like this in the csv file:
Regular Season,2010-06-31,Chicago,Road,22,37,21,28,,,,,108,240,39,79
My schema looks like this:
_Dataset: STRING
_DATE: DATE
_TEAMS: STRING
_VENUE: STRING
_1Q: INTEGER
_2Q: INTEGER
_3Q: INTEGER
_4Q: INTEGER
_OT1: INTEGER
_OT2: INTEGER
_OT3: INTEGER
_OT4: INTEGER
_F: INTEGER
_MIN: INTEGER
_FG: INTEGER
_FGA: INTEGER
Thanks in advance for your help
Even though June 31 exists as per The Thirty-first of June by J.B. Priestley -
your issue can be simply just because in reality - June month has only 30 days, so load engine gets stuck with June 31st
On the other hand - query engine successfully "translates" 2010-06-31 into 2010-07-01 - try below example
SELECT DATE('2010-06-31')

Converting string to timestamp in DB2 with to many fractions of a second

I am trying to convert a string on the on the following format to a timestamp in DB2: 2015-09-07T09:15:25.4788396+04:00
Problem is, DB2 only seems to handle 6 digit fractional seconds, not 7 as in my case. Any thoughts on a good workaround?
The format you have there matches the xs:dateTime pattern from XML. You can use this to your advantage and use implied XML parsing:
SELECT XMLCAST(XMLCAST('2015-09-07T09:15:25.4788396+04:00' AS XML) AS TIMESTAMP)
FROM SYSIBM.SYSDUMMY1
1
--------------------------
2015-09-07-05:15:25.478839
Note the timestamp returned is in UTC, add + CURRENT TIMEZONE to return it as a local timestamp. Tested on DB2 z/OS DSN10015.
You will need to parse the timezone from the string. Once you have that you can get the UTC time from subtracting from "current timezone" then add the parsed timezone to it as shown below. You will also need to use REPLACE to change T to a dash and colons to dots.
SELECT (TIMESTAMP('2015-09-07-09.15.25.4788396') - (current timezone)) + 4 hours FROM sysibm.sysdummy1;

Convert a Date field into Week Number in IBM DB2

I have a Date field (CHAR Datatype) which has values in this format: YYYYMMDD.
For example 20140729.
I want to convert it into a Weeknumber in format YYYYWKNO
For example, the result would be 201432.
How this can be done in IBM DB2?
Luckily for you, DB2 has some pretty good date formatting functions. Although the links for the documentation are for DB2 for Linux/Unix/Windows, it will also work on DB2 for z/OS.
You can use TIMESTAMP_FORMAT() to convert your CHAR field to an actual date, which you can then use VARCHAR_FORMAT() to format it in the way you wish:
SELECT
VARCHAR_FORMAT(
TIMESTAMP_FORMAT(
'20140801'
,'YYYYMMDD'
)
,'YYYYWW'
)
FROM SYSIBM.SYSDUMMY1
There are two different formats for "week", one is WW, which will give the week based on a week beginning with January 1 and ending January 7, and IW, which will give the ISO Week.. Please see the documentation page for VARCHAR_FORMAT for the other formats available.
The following gets week 31 instead of 32. But overall I think it is a good solution for this problem:
SELECT TO_DATE('20140801', 'YYYYMMDD') AS MYDATE
, YEAR(TO_DATE('20140801', 'YYYYMMDD')) * 100 + WEEK(TO_DATE('20140801', 'YYYYMMDD')) AS YYYYWKNO
FROM SYSIBM.SYSDUMMY1

Microsoft Hex dates

I have the following from a Microsoft SQL Server database for date/time value:
0x00009CEF00A25634
I found this post:
Help me translate long value, expressed in hex, back in to a date/time
Which seemed to be on the right track but by using the code I didn't get the right dates, are my hex dates in a different format? How would I convert them to a normal date, I am using PHP/PostgreSQL.
select CAST (0x00009CEF00A25634 as datetime) gives 2009-12-30 09:51:03.000
This is two integers. One for the date part 0x00009CEF (decimal 40175) and one for the time part 00A25634 (decimal 10638900). The date part is a signed integer giving number of days since 1 Jan 1900. The time part is an integer representing number of ticks.
There are 300 ticks in a second.
It can be seen that the following also returns the same result
SELECT DATEADD(MILLISECOND,10638900*10/3.0, DATEADD(DAY,40175, '19000101'))
You will need to figure out how to apply this to postgres.
Edit: an answer here apparently does this. I haven't tested it myself.
This works for me while migrating from SQL to MySQL :
SELECT (CAST('1900-01-01 00:00:00' + INTERVAL CAST(CONV(substr(HEX( 0x0000A249004576D0 ),1,8), 16, 10) AS SIGNED) DAY + INTERVAL CAST(CONV(substr(HEX( 0x0000A249004576D0 ),9,8), 16, 10) AS SIGNED)* 10000/3 MICROSECOND AS DATETIME)) AS newdate