Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date problem

Status
Not open for further replies.

zenit

Programmer
Joined
Jul 11, 2005
Messages
3
Location
US
I have 3 int :
- a year
- a weekday (1 to 7)
- a week (1 to 52)

and I need to find out the corresponding date DD/MM/YYYY

How can I do ?
 
Hi!

Take a look to the DATEPART ( "dw" , date ) function and
DATEADD("wk",XXX,date) function in the help. First will allow you to increment date by 1 until you reach the require day of week, second will increment date by number of weeks.


Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Hi,

I have used DATEPART to have my 3 numbers,
and now I want to do the opposite operation

but I have no date to start with

For example I have 2 , 6 , 2001
which is the 2nd day (tuesday since 1 is monday) of the 6th week of 2001
and I whish to know how to find out that it corresponds to
06/02/2001 (DD/MM/YYYY)
 
Check what is a value of the 01/01/YYYY in that year. DATEADD() will add required number of weeks, then accordingly to the day number returned by DATEPART("dw",...) for 01/01/YYYY do adjustment to the date using the passed week day number.
Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
OK !

Thanks
 

You can find the date with the following SQL script.

--Declare variables and assign values
Declare @year int, @week int, @day int, @thedate datetime
Select @year=2001, @week=40, @day=3

--Use built-in date and string functions to determine date
Set @thedate=dateadd(weekday,@day-1,dateadd(week,@week-1,'01/01/'+ltrim(str(2001))))

--Print result
Print @thedate Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top