I know this has been asked several times and I consulted/searched the offered questions and answers. I also read up the databricks docu and had several attempts, but I just don't get the desired result.
Given:
+----------------------------+
| data_type |
+----------------------------+
| timestamp |
+----------------------------+
Ex:
+------------------------------+
| data_value |
+------------------------------+
| 2017-11-22T00:00:00.000+0000 |
+------------------------------+
Desired outcome:
+----------------------------+
| data_value |
+----------------------------+
| 22.11.2017 |
+----------------------------+
What I tried and failed so far:
date_format(date_value, 'dd.mm.yyyy') AS MFGDate,
to_date(date_value) AS MFGDate,
date(date_value) AS MFGDate
Result:
+-------------------------+------------+
| MFGDate | MFGDate | MFGDate |
+------------+------------+------------+
| 22.00.2017 | 2017-11-22 | 2017-11-22 |
+------------+------------+------------+
Here's the full query:
SELECT
'01 FUV' AS Stage,
d1.ps_name AS FUV,
d1.ps_name AS LOT,
d2.date_value AS MFGDate
FROM
table d1
INNER JOIN table d2 ON d1.ag_id = d2.ag_id
AND d1.ag_path = d2.ag_path
AND d1.ps_name = d2.ps_name
WHERE
d1.AG_PATH LIKE "sourcepath'
Result:
+--------+--------+--------+------------------------------+
| Stage | FUV | Lot | MFGDate |
+--------+--------+--------+------------------------------+
| 01 FUV | A1U079 | A1U079 | 2019-03-27T00:00:00.000+0000 |
| 01 FUV | A1U255 | A1U255 | 2019-06-22T00:00:00.000+0000 |
| 01 FUV | A1U255 | A1U255 | 2019-11-10T00:00:00.000+0000 |
How to get the value for column MFGDate in the format like: 22.11.2017 ?