Quantcast
Channel: SCN : Discussion List - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 5653

How to determine of Week of the month in HANA SQL?

$
0
0

Hi,

 

Please can you tell me how can i determine the week for a particular month,starting from Sunday.

 

I have written script in HANA as :

 

SELECT WEEK(TO_DATE ('2013-03-01', 'YYYY-MM-DD'))

- WEEK(ADD_DAYS(TO_DATE ('2013-03-01', 'YYYY-MM-DD'),-(DAYOFMONTH(TO_DATE ('2013-03-01', 'YYYY-MM-DD'))-1)))+1 FROM DUMMY;

 

But it doesn't seem accurate, it fails for date 2013-03-31, as the week number should be 6.

 

 

in SQL similar functionality is achieved by (for week starting from Monday):

 

SELECT WEEK(my_date_field,5) - WEEK(DATE_SUB(my_date_field, INTERVAL DAYOFMONTH(my_date_field)-1 DAY),5)+1

 

link for SQL code : http://think-robot.com/2009/04/week-of-the-month-in-mysql/

 

Please help!

 

Regards

Sushant


Viewing all articles
Browse latest Browse all 5653

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>