By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,635 Members | 913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,635 IT Pros & Developers. It's quick & easy.

weeknumber in sql??

P: n/a
DD
Hi there,

I am working on a sql-query and I need to know the weeknumber of a given
date. Could anyone please help me with this.

Thanks in advance,

Arjen
Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Something like this?

SELECT [theDate] & " is in " & Format([theDate],"w") & "th wheek of year"
AS Weekday FROM theTable;
"DD" <ad@ad.nl> escreveu na mensagem
news:bn**********@news4.tilbu1.nb.home.nl...
Hi there,

I am working on a sql-query and I need to know the weeknumber of a given
date. Could anyone please help me with this.

Thanks in advance,

Arjen

Nov 12 '05 #2

P: n/a
"DD" <ad@ad.nl> wrote in message news:<bn**********@news4.tilbu1.nb.home.nl>...
Hi there,

I am working on a sql-query and I need to know the weeknumber of a given
date. Could anyone please help me with this.

Thanks in advance,

Arjen


Something like...
Public Function WeekNumber(ByVal dtDate As Date) As Integer
WeekNumber = DateDiff("w", DateSerial(Year(dtDate), 1, 1), dtDate) + 1

End Function

....maybe?

Or were you thinking of a pure SQL function?
Nov 12 '05 #3

P: n/a
On Fri, 31 Oct 2003 15:48:03 +0100, "DD" <ad@ad.nl> wrote:

Use the DateDiff function, especially the last two arguments.
Reasonable people can disagree on what constitutes week 1. Make sure
you make the right selection for your situation.

-Tom.

Hi there,

I am working on a sql-query and I need to know the weeknumber of a given
date. Could anyone please help me with this.

Thanks in advance,

Arjen


Nov 12 '05 #4

P: n/a
Access or Sql Server?

For Sql Server you can do this:

SELECT 'Week ' + datename(wk, myTable.myField)) AS 'someWeek'
FROM myTable

As for Access - I looked around for a while, but didn't see any built in
functions that would do it. One of the others recommendations might work
there.


"DD" <ad@ad.nl> wrote in message
news:bn**********@news4.tilbu1.nb.home.nl...
Hi there,

I am working on a sql-query and I need to know the weeknumber of a given
date. Could anyone please help me with this.

Thanks in advance,

Arjen

Nov 12 '05 #5

P: n/a
Access - DatePart("ww", myTable.myField) As WeekOfYear

--
MGFoster:::mgf
Oakland, CA (USA)
Jerry Boone wrote:
Access or Sql Server?

For Sql Server you can do this:

SELECT 'Week ' + datename(wk, myTable.myField)) AS 'someWeek'
FROM myTable

As for Access - I looked around for a while, but didn't see any built in
functions that would do it. One of the others recommendations might work
there.


"DD" <ad@ad.nl> wrote in message
news:bn**********@news4.tilbu1.nb.home.nl...
Hi there,

I am working on a sql-query and I need to know the weeknumber of a given
date. Could anyone please help me with this.

Thanks in advance,

Arjen



Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.