SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 datepart(wk, date) not working properly
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

learning_grsql
Posting Yak Master

218 Posts

Posted - 01/11/2014 :  05:19:39  Show Profile  Reply with Quote
Hi,
When I use the following query, it shows only dates from 1st Jan 2014 to 4th Jan 2014, but week 1 should have been 30th Dec to Jan 5th. Can you tell me where I'm doing wrong?


select date from table
where datepart(wk,date) = 1

Edited by - learning_grsql on 01/11/2014 05:20:41

khtan
In (Som, Ni, Yak)

Singapore
17438 Posts

Posted - 01/11/2014 :  08:24:02  Show Profile  Reply with Quote
what you want is iso_week

datepart(iso_week,date)



KH
Time is always against us

Go to Top of Page

learning_grsql
Posting Yak Master

218 Posts

Posted - 01/11/2014 :  09:45:30  Show Profile  Reply with Quote
I'm using 2005 sql server. iso_week is not a recognized option
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 01/11/2014 :  12:39:29  Show Profile  Reply with Quote
so whats your exact requirement?to get all days in 1st week of year?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

learning_grsql
Posting Yak Master

218 Posts

Posted - 01/12/2014 :  06:13:11  Show Profile  Reply with Quote
Hi Visakh16, I want to extract a data for 1st week of this year. My query looks like below.

select date, sum(price) from table
where datepart(wk,date) = 1
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17438 Posts

Posted - 01/12/2014 :  06:27:02  Show Profile  Reply with Quote
quote:
Originally posted by learning_grsql

I'm using 2005 sql server. iso_week is not a recognized option


use this
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=60510


KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000