how do I convert mmyy to last day of month in netezza

别等时光非礼了梦想. 提交于 2019-12-25 02:22:02

问题


One of my column needs to be transformed into a date field. It contains a value that gives the YYMM and it should be translated into the last day of that month: For example, 1312 should become 12/31/2013.

I have tried various last_day, to_char functions but not able to convert 1312 in a date format. Please help !!


回答1:


Netezza is based on Postgres, so maybe the Postgres method will work. Here is Postgres code that works (see here):

select to_date('1312'||'01', 'YYMMDD') + interval '1 month' - interval '1 day'



回答2:


I would first convert the number to a date, then add 1 month and subtract 1 day.

select add_months(to_date(1312, 'yymm'), 1) - 1 as the_date


来源:https://stackoverflow.com/questions/22566950/how-do-i-convert-mmyy-to-last-day-of-month-in-netezza

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!