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

2019-09-17 10: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 !!

2条回答
Summer. ? 凉城
2楼-- · 2019-09-17 10:30

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'
查看更多
Juvenile、少年°
3楼-- · 2019-09-17 10:31

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
查看更多
登录 后发表回答