Home > Software engineering >  How to convert 6 digit decimal to date format (SQL)
How to convert 6 digit decimal to date format (SQL)

Time:06-05

Would like to convert 6 digit decimal e.g. 310322 (ddmmyy) to Date Format to 2022-03-31?

Thank you.

CodePudding user response:

Please specify what language you are using, I will share in python. You just have to separate the elements by positions and convert in the format that you want to use, in this case as you can see i added the timezone UTC for better format:

Decimal_value = 310322
Year = int(decimal_value[4:5])
month = int(decimal_value[2:3])
day = int(decimal_value[0:1])

Date_format = datetime(day, month, year).replace(tzinfo=timezone.utc)

CodePudding user response:

In Impala you have to convert it into a timestamp and then do to_date

 select to_date(to_timestamp('310322', 'DDMMYY'),'YYYY-MM-DD');
  • Related