HANA SQL获取当前月的第一天

时间:2022-01-07 16:57:33
SELECT ADD_DAYS(CURRENT_DATE,-EXTRACT(DAY FROM CURRENT_DATE) + 1) FROM DUMMY; 


SELECT ADD_MONTHS(NEXT_DAY(LAST_DAY(CURRENT_DATE)),-1) FROM DUMMY;

SELECT ADD_DAYS(LAST_DAY(ADD_MONTHS(CURRENT_DATE,-1)),1) FROM DUMMY;

方法有很多种,这里只列出了常用的几种。

找到了几个比较好的写法,请参考

Guys ,
Few common HANA SQL logic I Know
 
first day of month: ADD_DAYS(LAST_DAY(ADD_MONTHS(CURRENT_DATE,-1)),1)
last day of month: LAST_DAY (CURRENT_DATE)
first day of quarter: ADD_DAYS( ADD_MONTHS( CURRENT_DATE,(MOD( MONTH(CURRENT_DATE) -1, 3 )) * -1) ,DAYOFMONTH(CURRENT_DATE)* -1 + 1 )
first day of year: ADD_DAYS(CURRENT_DATE, DAYOFYEAR (CURRENT_DATE)* -1 + 1)
last day of Prior year:ADD_DAYS(CURRENT_DATE, DAYOFYEAR (CURRENT_DATE)* -1 )
 
 
 
direct Filter / Where clause
Current Month: to_char(TIME_DIMENSION.Column_DATE,'YYYYMM' ) = to_char(CURRENT_DATE,'YYYYMM' )
Current Quarter: {fn Quarter(TIME_DIMENSION.Column_DATE)} = {fn QUARTER(CURRENT_DATE)}
Current Year: {fn year(TIME_DIMENSION.Column_DATE)} = {fn year(CURRENT_DATE)}