2

The below query is returning 2017-02-23 00:45:00 instead of 12:45.

spark.sql("select from_unixtime(unix_timestamp(('2017-02-23 12:45:00')," +
          "'yyyy-MM-dd hh:mm:ss'))").show(false)

But the below query is returning expected output

2017-02-23 13:45:00

spark.sql("select from_unixtime(unix_timestamp(('2017-02-23 13:45:00')," +
          "'yyyy-MM-dd hh:mm:ss'))").show(false)

Can some one please help?

Michael Lang
  • 3,902
  • 1
  • 23
  • 37
Dinesh J
  • 135
  • 2
  • 6

1 Answers1

1

You should be using capital h as HH:mm:ss

spark.sql("select from_unixtime(unix_timestamp(('2017-02-23 12:45:00'),'yyyy-MM-dd HH:mm:ss')) AS date").show(false)

which should give you

+-------------------+
|date               |
+-------------------+
|2017-02-23 12:45:00|
+-------------------+

You can get more info here

Ramesh Maharjan
  • 41,071
  • 6
  • 69
  • 97
  • May I know what is the difference between HhH and hh – Dinesh J Mar 22 '18 at 06:01
  • yes sure you can find more detail in the link that I updated in the question or look at https://stackoverflow.com/questions/17341214/difference-between-java-hhmm-and-hhmm-on-simpledateformat – Ramesh Maharjan Mar 22 '18 at 06:03