0

I have two columns which are in string but need to be converted into a datetime or date and time.

- Column1: 20190828T121539.000000+0200
- Column2: 20190828T121539.000+0200

How can I do this?

I used:

.withColumn('test', from_unixtime(unix_timestamp('Column1', 'yyyyMMddThhmmss'))

but doesn't seem to work


I've solved it with this:

to_timestamp(col('EventDateTime').substr(1,15), "yyyyMMdd'T'HHmmss")

The last part of the value was irrelevant so I could use a substr

Kristof
  • 31
  • 5
  • 2
    Possible duplicate of [Convert pyspark string to date format](https://stackoverflow.com/questions/38080748/convert-pyspark-string-to-date-format) – Mike Doe Sep 04 '19 at 11:54
  • 1
    Your format is not the same as the actual structure of your datetimes. You have `yyyyMMddThhmmss.(something)` – Sotos Sep 04 '19 at 11:57

0 Answers0