datetime - Current week in current month showing wrong in SQL Server -


this how july month looks like.

enter image description here

i trying pick current week in current month getdate() parameter using below code.

declare @date datetime = getdate() select datepart(day, datediff(day, 0, @date) / 7 * 7) / 7 + 1  

expecting result

date       -> week number 2015-07-01 -> 1 2015-07-06 -> 2 2015-07-13 -> 3 

but, instead, result is:

date       -> week number 2015-07-01 -> 5 2015-07-06 -> 1 2015-07-13 -> 2 

how first format in sql server?

thanks in advance

this seems right answer

select datediff(week, dateadd(week, datediff(week, 0, dateadd(month, datediff(month, 0, @date), 0)), 0), @date)+1 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -