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')
Related
I'm working on tables obtained from a PervasiveSQL database and I have some trouble managing dates.
In some of the fields dates are recorded in the format we use in Italy, dd/mm/yyyy, but in others are recorded in a format I can't understand, something like this:
Start_Date 132384788
Last_Tx_Date 132385052
Last_Tx_Time 252711936
What kind of format is it?
How can I convert it in a human readable one?
I think that Start_Date could be August 8 2020 but I'm not sure.
Thanks for any help!
I tried to copy and paste tables in an Excel file but automatic dates conversion did not work.
The Start_Date and Last_Tx_Date fields look to be Btrieve Date fields. If you set the data type for that field in the DDFs to Date, it should show a human readable field. However the Last_Tx_Time field is a Btrieve Time (not timestamp) type.
From the Actian Zen v15.10 documentation (https://docs.actian.com/zen/v15/#page/sqlref/sqldtype.htm#ww136646):
Date:
The DATE key type is stored internally as a 4-byte value. The day and the month are each stored in 1-byte binary format. The year is a 2-byte binary number that represents the entire year value. The MicroKernel places the day into the first byte, the month into the second byte, and the year into a two-byte word following the month.
An example of C structure used for date fields would be:
TYPE dateField {
char day;
char month;
integer year;
}
The year portion of a date field is expected to be set to the integer representation of the entire year. For example, 2,001 for the year 2001.
Time:
The TIME key type is stored internally as a 4-byte value. Hundredths of a second, second, minute, and hour values are each stored in 1-byte binary format. The MicroKernel places the hundredths of a second value in the first byte, followed respectively by the second, minute, and hour values. The data format is hh:mm:ss.nn. Supported values range from 00:00:00.00 to 23:59:59.99.
I exported data from an SQLite table to a CSV file. The data includes a timestamp with at least one-minute resolution: "2019-11-15 01:30:06". The data is actually stored as a Julian date, in this case 2458802.35424295. I imported the data into a double-precision field. I need to convert that number into a timestamp with time zone. I tried casting the double-precision number to text and then using to_timestamp(), but that appears to work only with integer days. I can get a timestamp, but it is always at midnight of the correct date. I tried using to_timestamp() passing in my number, but that returns an epoch (number of milliseconds since 1/1/1970).
I could try to take the fractional part of my Julian date value, calculate the number of milliseconds since midnight that represents, use the to_timestamp(text,text) method to get the date I need, and then add the epoch since midnight to that date. But that's awfully cumbersome. Isn't there a better way?
I'm using PostgreSQL 9.3.
NOTE: The simple answer to my problem, which occured to me just before I clicked the Post button, is to export the data in the form I want, using SQLite's datetime() function to convert the number to a date string during export. But I remain curious. I would have thought there would be a standard way to do this conversion.
I am extracting three values (server, region, max(date)) from my postgresql> But I want to extract an additional 4th field which should be the numerical addition of 1 to 3rd field. I am unable to use date add function as in the database date field is defined as an integer.
date type in DB
date|integer|not null
tried using cast and date add function
MAX(s.date)::date + cast('1 day' as interval)
Error Received
ERROR: cannot cast type integer to date
Required output
select server, region, max(alarm_date), next date from table .....
testserver, europe, 20190901, 20190902
testserver2, europe, 20191001, 20191002
next date value should be the addition to alarm_date
To convert an integer like 20190901 to a date, use something like
to_date(CAST(s.date AS text), 'YYYYMMDD')
It is a bad idea to store dates as integers like that. Using the date data type will prevent corrupted data from entering the database, and it will make all operations natural.
First solution that came to my mind:
select (20190901::varchar)::date + 1
Which output 2019-09-02 as type date.
Other solutions can be found here.
I am trying to extract a month from a date in SAS, but so far all my new month variables are coming up as missing.
I have attempted to use some combinations of the month() function in SAS, but so far it just comes up as missing. The dates are formatted as follows: 01/31/2017 (MMDDYY10.)
I have tried
month = month(end_date)
Month =catx('/',put(month(end_date),z2
I would like the Month to show up as a number (01) or a 3 letter code (JAN), currently it is just missing (.)
Thanks in advance!
For month() to return a missing value the end_date variable must be numeric and missing. If end_date were a character variable the log would show invalid numeric data.
Use the monname3. format to convert a date value to a $3. character value mon
monthname = put (end_date, monname3.);
Other alternatives are:
keep the date value unchanged and change the format, or
map the date value to the first of the month value and also format that
For example:
end_date_copy = end_date;
format end_date_copy monname3.;
end_date_month = intnx('month', end_date, 0);
format end_date_month monname3.;
What you ultimately do depends on how the mon is to be used downstream in reporting or aggregating.
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.