Is it possible to hint PAW that the integer value in result is timestamp and replace it with datetime automatically?
Related
I am working locally with an sqllite DB. I have imported some records from teradata where there was a date field in the format of 'YYYY-MM-DD'. When i imported the records the date switched from a date to a number. I know this is a feature of sqllite and that one can access it via date(sqllite_date) when selecting it in a where clause.
My problem is that the dates now appear to be a bit odd. For example the year appears to be negative.
Is there anyway to recover this to the correct format?
Below is an example of converting a number in the database into a date
SELECT date(18386)
# -4662-03-28
SELECT datetime('now')
# 2021-02-11 10:41:52
SELECT date(sqllite_date) FROM mydb
# Returns -4662-03-28
# Should return 2020-05-04
I am very new to this area so apologies if this is a basic question. Thank you very much for your time
In SQLite you can store dates as TEXT, REAL or INTEGER.
It seems that you stored the dates in a column with INTEGER or REAL affinity.
In this case, if you use the function date(), it considers a value like 18386 as a Julian day, meaning the number of days since noon in Greenwich on November 24, 4714 B.C.
This is why date(18386) returns 4662-03-28B.C.
But I suspect that the date values that you have are the number of days since '1970-01-01'.
In this case, 18386 days after '1970-01-01' is '2020-05-04'.
So you can get the dates in the format YYYY-MM-DD if you add the value of your column as days to '1970-01-01':
SELECT date('1970-01-01', datecolumn || ' day') FROM tablename
Or by transforming your date values to seconds and treat them as UNIX time (the number of seconds since '1970-01-01 00:00:00 UTC'):
SELECT date(datecolumn * 24 * 3600, 'unixepoch') FROM tablename
Replace datecolumn with the name of your column.
I want to convert the string to DateTime.
My strings look like this:
19.03.2020 08:14:13
09.07.2020 07:32:39
I used these queries:
PARSE_DATETIME('%d.%m.%Y %H:%M:%S', Date) AS NF_spent_date,
and
PARSE_DATETIME('%d.%m.%Y %T', Date) AS NF_spent_date,
but the result in both cases is
2020-03-19T08:14:13
2020-07-09T07:32:39
How can I avoid the T letter in the output??
This is how Google BigQuery displays DATETIME values. You can use PARSE_TIMESTAMP to convert to TIMESTAMP instead which is displayed without T but with UTC at the end:
select PARSE_TIMESTAMP('%d.%m.%Y %H:%M:%S', '19.03.2020 08:14:13') AS NF_spent_date
I transfer the data into Tera Data with fastload now in one column 'ENDDATE' There are 2 values stored 'NULL' and Timestamp value like format
YYYY-MM-DDBHH:MI:SS
I want to transfer both values into new table
I want to NULL value replace with something and other Timestamp data to date format like
YYYY-MM-DD
How to transfer both values into table?
I want to select the dates in ascending order. Dates are stored in dd-MMM-yy(02-Mar-12) format. Here is my query:
SELECT EventDate,Event,ID from EventCalenderTable Order By EventDate ASC
output is:
10-03-12
12-02-12
15-01-12
18-07-12
But the output should like:
15-01-12
12-02-12
10-03-12
18-07-12
Event Date is date datatype.
I have seen number of post about storing date in sql. I noticed that Convert function done the tricks in sql server. But how can I do this in Sqlite??
Thanks in advance.
SQLite only knows three date formats:
Text ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS")
Real Julian day numbers since November 24, 4714 B.C
Integer number of seconds since 1970-01-01 00:00:00 UTC
SQLite does have five date/time functions for converting between formats.
I am being passed a date in this format DepartDate=40683, in vb.net
however i cant figure out how to convert the integer into a regular date
Assuming, you're under SQL SERVER:
SQL Server uses 8 bytes to store the
datetime data type. The first 4 bytes
make up an integer value that
represents the number of days since
January 1, 1900.
The second 4 bytes are an integer
value that represents the number of
milliseconds since midnight.
So assigning this value(40683) to a datetime variable, you'll get a 2011-05-22 00:00:00.000 as date value.
If it's an SQL Server it's likely the internal storage format of the date that you are getting, which is the number of days since 1900-01-01. You can use the DateTime.AddDays method to convert it. Example:
Dim n as Integer = 40683
Dim DepartDate As DateTime = New DateTime(1900, 1, 1).AddDays(n)