Week number in SQL query?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Week number in SQL query?

  1. #1
    Florien Guest

    Week number in SQL query?


    Hi everyone,

    I'm running an Access database with the fields "PublicationYear" and "PublicationWeek"
    in it. The first holding 4-digit year values, second 2-digit week values.

    Problem: I need to be able to select all the records from the database that
    correspond to the current week number (company works ahead and also adds
    records for the weeks to come).

    Question: How do I calculate the current week number so I can include this
    value into my SQL query? The year thing is easy, but I really don't know
    how to go about the week number of the current date.

    Can anyone help me?

    Thanx, Florien

  2. #2
    Glenn Guest

    Re: Week number in SQL query?


    "Florien" <florien@chello.nl> wrote:
    >
    >Hi everyone,
    >
    >I'm running an Access database with the fields "PublicationYear" and "PublicationWeek"
    >in it. The first holding 4-digit year values, second 2-digit week values.
    >
    >Problem: I need to be able to select all the records from the database that
    >correspond to the current week number (company works ahead and also adds
    >records for the weeks to come).
    >
    >Question: How do I calculate the current week number so I can include this
    >value into my SQL query? The year thing is easy, but I really don't know
    >how to go about the week number of the current date.
    >
    >Can anyone help me?
    >
    >Thanx, Florien

    Check out the datediff and maybe the dateadd function in vbscript

  3. #3
    Dirk Guest

    Re: Week number in SQL query?


    This may or may not be of any use to you. Microsoft SQL Server has a function
    called DATEPART(). The following SELECT statement will return the week number
    for the current week. You may what to see if Access has the same or similar
    function.

    SELECT DATEPART( wk, GETDATE() )

    GETDATE() is another function which returns the current date and time.

    - Dirk



    "Florien" <florien@chello.nl> wrote:
    >
    >Hi everyone,
    >
    >I'm running an Access database with the fields "PublicationYear" and "PublicationWeek"
    >in it. The first holding 4-digit year values, second 2-digit week values.
    >
    >Problem: I need to be able to select all the records from the database that
    >correspond to the current week number (company works ahead and also adds
    >records for the weeks to come).
    >
    >Question: How do I calculate the current week number so I can include this
    >value into my SQL query? The year thing is easy, but I really don't know
    >how to go about the week number of the current date.
    >
    >Can anyone help me?
    >
    >Thanx, Florien



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center