2

Input looks like:

2017-07-03

Expected output looks like:

20170703

I tried the below code:

year(2017-07-03) * 10000 + month(2017-07-03) * 100 + day(2017-07-03))

Is there any built-in function that can do this conversion?

Thank you

Tripp Kinetics
  • 5,178
  • 2
  • 23
  • 37
hoboken 711
  • 21
  • 1
  • 2

2 Answers2

0

You can use from_unixtime and unix_timestamp with cast to do this.

select cast(from_unixtime(unix_timestamp('2017-07-03','yyyy-MM-dd'),'yyyyMMdd') as int)
Vamsi Prabhala
  • 48,685
  • 4
  • 36
  • 58
-1

You can split on '-', then concatenate back again. Or replace "-" with "".

regexp_replace("2017-07-03", "-", "")

See how to replace characters in hive?

Acccumulation
  • 3,491
  • 1
  • 8
  • 12