weeknumber in sql??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DD

    #1

    weeknumber in sql??

    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


  • Roberto Spier

    #2
    Re: weeknumber in sql??

    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:bntsn3$75i $1@news4.tilbu1 .nb.home.nl...[color=blue]
    > 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
    >
    >[/color]


    Comment

    • Pieter Linden

      #3
      Re: weeknumber in sql??

      "DD" <ad@ad.nl> wrote in message news:<bntsn3$75 i$1@news4.tilbu 1.nb.home.nl>.. .[color=blue]
      > 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[/color]

      Something like...
      Public Function WeekNumber(ByVa l 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?

      Comment

      • Tom van Stiphout

        #4
        Re: weeknumber in sql??

        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.

        [color=blue]
        > 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
        >[/color]

        Comment

        • Jerry Boone

          #5
          Re: weeknumber in sql??

          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:bntsn3$75i $1@news4.tilbu1 .nb.home.nl...[color=blue]
          > 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
          >
          >
          >[/color]


          Comment

          • MGFoster

            #6
            Re: weeknumber in sql??

            Access - DatePart("ww", myTable.myField ) As WeekOfYear

            --
            MGFoster:::mgf
            Oakland, CA (USA)


            Jerry Boone wrote:[color=blue]
            > 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:bntsn3$75i $1@news4.tilbu1 .nb.home.nl...
            >[color=green]
            >>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
            >>
            >>
            >>[/color]
            >
            >
            >[/color]

            Comment

            Working...