How to covert a string to date format ddmonyyyy [duplicate] - apache-spark-sql

This question already has answers here:
Convert pyspark string to date format
(6 answers)
Closed 2 years ago.
I have a string containing date in it.
It looks like:
01JAN2020
02FEB2020
I use the following code to parse it to date format but didn't succeed:
a= a.withColumn('dt_one', to_date(unix_timestamp(col('dt_one'), 'dLy').cast("timestamp")))
Do you know the right syntax to do this?
Thanks!

I think this should work:
a= a.withColumn('dt_one', to_date(unix_timestamp(col('dt_one'), 'dMMMy').cast("timestamp")))

Related

HIVE SQL ISO timestamp. how to convert from string to numeric continuous? [duplicate]

This question already has answers here:
Hive: Convert string datetime with missing seconds in "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
(2 answers)
How to convert "2019-11-02T20:18:00Z" to timestamp in HQL?
(2 answers)
How to convert ISO Date to UTC date in Hive
(1 answer)
Closed 1 year ago.
So I have a timestamp column that is formatted as a string and looks like this:
2021-06-07T05:00:52.000000Z
Any advice on how I can get this converted to a normal numeric continuous timestamp?
How to deal with the "T" and the "Z"?

Convert String to Date Google BigQuery [duplicate]

This question already has answers here:
parse date form string in bigquery
(2 answers)
Closed 4 years ago.
I have a string row like this: 20190116.
How I can convert it to Date?
You can easily do this with PARSE_DATE function in standard SQL. For your example, you can do this:
#standardSQL
SELECT PARSE_DATE('%Y%m%d','20190116')

SQLITE date formate [duplicate]

This question already has answers here:
Sqlite convert string to date
(9 answers)
Reformat dates in column
(2 answers)
sqlite change date format of every cell in column
(1 answer)
How can I convert the Date format for column in sqlite table?
(1 answer)
Closed 5 years ago.
I am currently working on a project that utilizes SQLite. I need to covert a stored date format from MM/DD/YYYY to YYYY/MM/DD. However, I don't know how to convert in SQLite.
Please take a look here:
https://sqlite.org/lang_datefunc.html
What you need is strftime function to specify the format.

trimming a datetime field for an entire column [duplicate]

This question already has answers here:
Convert SQL Server Date to mm-yyyy
(4 answers)
Closed 6 years ago.
I have an entire column that I would like to change from a complete datetime field to display only the mm-yyyy.
Don't store it in database. Let your column stay as datetime datatype use the below code to display the date in mm-yyyy format
Select right(convert(char(10),getdate(),105),7)

How to retrieve DateTime from a Timestamp column in a table in SQL? [duplicate]

This question already has answers here:
How to convert SQL Server's timestamp column to datetime format
(14 answers)
Closed 9 years ago.
I am using following query but it doesn't provide any meaningful output:
Select Cast(versionno as bigint) from BranchDetail
The value in Version column is like this : 0x000000000D2537F7
A TIMESTAMP has nothing to do with date and time. See this question. It is a ROWVERSION, not a date/time value.