SQL Query to find the last day of the month

前端 未结 14 1814
太阳男子
太阳男子 2020-11-27 04:40

I need to find the last day of a month in the following format:

\"2013-05-31 00:00:00:000\"

Anybody please help out.

14条回答
  •  囚心锁ツ
    2020-11-27 05:22

    In Snowflake (and likely other SQL engines), you can use LAST_DAY.

    select to_date('2015-05-08T23:39:20.123-07:00') as "DATE",
           last_day("DATE", 'MONTH') as "LAST DAY OF MONTH";
    

    Which returns:

    DATE         LAST DAY OF MONTH
    2015-05-08          2015-05-31
    

提交回复
热议问题