3

I can get year and month separately in Athena but i don't know how to get YEARMONTH from date.

select year(date1) from table1
select Month(date1) from table1

Please suggest how to get YEARMONTH. Thank you in advance.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Dee
  • 31
  • 1
  • 1
  • 5

1 Answers1

3

You can use date_format to represent your date in needed format:

select date_format(now(), '%Y%m')
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
  • How to use same query in DBeaver 7.1.2 version and in VANDYKE -EMR - SecureCRT? SELECT DATE_FORMAT(FIELD1,'%y%m' from table1 ? – Dee Jul 29 '21 at 22:48
  • @Dee not sure I fully understand your question. Have never used second one and in first one - as any other SQL query. – Guru Stron Jul 29 '21 at 22:51
  • i have multiple tools in company to get data and all are 3 different tools which i havent used it before.....so i need to keep writing queries in all 3 tools, and same query doesnt work in another tool. so just wondering if you are aware query for DBeaver tool and EMR tool to get YEARMONTH..... – Dee Jul 29 '21 at 22:56
  • thanks a lot for your help! I got the query for Dbeaver. select concat(date_part(year,field1), date_part(month, field1)) from table1. let me know if there are any better way to write this one..... – Dee Jul 29 '21 at 23:04