Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to get week from a datetime type column

Author  Topic 

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2009-05-13 : 08:39:53
Hi,
is there any function in sql server to get week from a datetime column

like is value is '01-01-2009' its hould display week = 1

Thanks for your attention.

Rahul Arora
NCCE, Panipat


######################
IMPOSSIBLE = I+M+POSSIBLE

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-13 : 08:40:49
See Books Online for DATEPART function.
To get an accurate answer, you will have to define what a week means to you.


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2009-05-13 : 09:02:13
hi peso thanks for reply, but i did the same and did nt get any satisfactory way for this task.
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2009-05-13 : 09:05:33
so doing this didn't give you an answer of 1?

select DATEPART(wk,'20090101')

Em
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2009-05-13 : 09:30:16
quote:
Originally posted by elancaster

so doing this didn't give you an answer of 1?

select DATEPART(wk,'20090101')

Em



Funny, that was in the first two lines of BOL\datepart functions.

quote:
Originally posted by Peso

See Books Online for DATEPART function.
To get an accurate answer, you will have to define what a week means to you.


E 12°55'05.63"
N 56°04'39.26"




Perhaps the OP didn't see Peso's first response??????

quote:
Originally posted by arorarahul.0688

hi peso thanks for reply, but i did the same and did nt get any satisfactory way for this task.



No, wait, they did. Perhaps you have a different version of BOL?? Or maybe no BOL at all? Or perhaps, didn't make an attempt to heed the advice already given???

Terry

-- Procrastinate now!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-13 : 09:45:17
There is a saying in Sweden that roughly translated goes
"You can lead a cow to the water, but you can't force it to drink."



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2009-05-13 : 09:47:21
In the U.S. it's a horse but obviously the same meaning behind the phrase.

Terry

-- Procrastinate now!
Go to Top of Page

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2009-05-13 : 10:00:19
quote:
Originally posted by tosscrosby

In the U.S. it's a horse but obviously the same meaning behind the phrase.

Terry

-- Procrastinate now!



Thanks to peso and all of guys. what i went wrong is i was taking week instead of wk in datepart function.
i did correction and wanted to share it with u and saw few more conversations. Thanks to all of your attention.
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2009-05-13 : 10:06:13
you mean you did...

select DATEPART(week,'20090101')
...?
funny, coz i still get 1

Em
Go to Top of Page

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2009-05-13 : 10:19:09
quote:
Originally posted by elancaster

you mean you did...

select DATEPART(week,'20090101')
...?
funny, coz i still get 1

Em



it may Be FUNNY but it worked the way i wanted.......
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2009-05-13 : 10:24:28
quote:
Originally posted by arorarahul.0688


Thanks to peso and all of guys. what i went wrong is i was taking week instead of wk in datepart function.
i did correction and wanted to share it with u and saw few more conversations. Thanks to all of your attention.



Would you be so kind to post your resolution? This could help others in the future.

Terry

-- Procrastinate now!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-13 : 10:36:37
quote:
Originally posted by arorarahul.0688

quote:
Originally posted by elancaster

you mean you did...

select DATEPART(week,'20090101')
...?
funny, coz i still get 1

Em



it may Be FUNNY but it worked the way i wanted.......


are you sure you used sql server? also which toll were you using to connect?
Go to Top of Page

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2009-05-14 : 03:46:10
quote:
Originally posted by visakh16

quote:
Originally posted by arorarahul.0688

quote:
Originally posted by elancaster

you mean you did...

select DATEPART(week,'20090101')
...?
funny, coz i still get 1

Em



it may Be FUNNY but it worked the way i wanted.......


are you sure you used sql server? also which toll were you using to connect?



Yes i am using sql server 2000 and QlikView the Business Intelligence tool for analysis.
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2009-05-14 : 08:12:58
quote:
Originally posted by tosscrosby

quote:
Originally posted by arorarahul.0688


Thanks to peso and all of guys. what i went wrong is i was taking week instead of wk in datepart function.
i did correction and wanted to share it with u and saw few more conversations. Thanks to all of your attention.



Would you be so kind to post your resolution? This could help others in the future.

Terry

-- Procrastinate now!




???

Terry

-- Procrastinate now!
Go to Top of Page
   

- Advertisement -