Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Location
    Spain
    Posts
    1

    Lightbulb Unanswered: obtain a date from week data

    Hi all,

    I have a problem with date functions...

    In my program I use weeks, and with this variable I need to know which is the first day of the selected week...

    For example... I put week 52 in my program... how I can obtain the first day of this week? -> (22/12/2003).

    I have proved with this functions...

    SET DATEFIRST 1 (to configure Monday as first day of week)

    SELECT DATEADD(ww,DATEDIFF(ww,0,GETDATE()),0)

    With this I have the day of the current week... but I can't put my week in this function... aarrgggg.

    Please help me...

    Thanks a lot.

  2. #2
    Join Date
    Sep 2003
    Location
    Dallas, Texas
    Posts
    311

    Re: obtain a date from week data

    declare @week tinyint, @firstdate varchar(4)
    -- Choose the week number
    set @week = 30
    -- Choose the year
    set @firstdate = '2003-01-01'
    select dateadd(day, (datepart(weekday, @firstdate) - 1) * -1, dateadd(week, @week, @firstdate))

  3. #3
    Join Date
    Sep 2003
    Location
    Dallas, Texas
    Posts
    311

    Re: obtain a date from week data

    Originally posted by joejcheng
    declare @week tinyint, @firstdate varchar(10)
    -- Choose the week number
    set @week = 30
    -- Choose the year
    set @firstdate = '2003-01-01'
    select dateadd(day, (datepart(weekday, @firstdate) - 1) * -1, dateadd(week, @week, @firstdate))

  4. #4
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Simply Outstanding .... why did I not think of it first ????
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •