I have this column called 'Date' that contains dates formatted this way: '20150101'.
I tried using sql substring, but when I run the query using 'date' function in sql, it doesn't work on the date format I have.
Here is the query I made:
SELECT (DATE ((SUBSTR(JOUR, 1, 4),
SUBSTR(JOUR, 5, 2),
SUBSTR(JOUR, 7, 2)))) As date
FROM TABLE
Any idea? I couldn't find anything similar to this date format! I found one that uses the convert function but it's not in StandardSQL or BigQuery
Convert Char 'yyyymmdd' back to Date data types in SQL Server. Now, convert the Character format 'yyyymmdd' to a Date and DateTime data type using CAST and CONVERT. --A. Cast and Convert datatype DATE: SELECT [CharDate], CAST([CharDate] AS DATE) as 'Date-CAST', CONVERT(DATE,[CharDate]) as 'Date-CONVERT' FROM [dbo].
Using strptime() , date and time in string format can be converted to datetime type. The first parameter is the string and the second is the date time format specifier. One advantage of converting to date format is one can select the month or date or time individually.
In BigQuery, dates and times can be one of the following datatypes: DATE : calendar date (e.g. 2020-01-01)
What about PARSE_DATE ?
SELECT PARSE_DATE("%Y%m%d", "20190101") as parsed;
For your table:
SELECT PARSE_DATE ("%Y%m%d", JOUR) As mydatecolumn from TABLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With