Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-09-25 : 08:14:28
|
| Tony writes "Hi guys,I've just started to work with SQL Server 2k and have a 'job' table as follows:jobid int identity primary key,enteredbyuser varchar(128) default user_name(),enteredondate datetime default getdate(),proddate datetime default dateadd(wk, 4, getdate()),prodweek int default datepart(wk,(dateadd(wk,4,getdate())),Now, in I'am trying to create a function which will accept a integer week number and return the corresponding week start datetime... is this possible... I am assuming that the week number entered will be relevant to current year at the time...Any pointers or help would be gratefully appreciated,Thanks, Tony" |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2003-09-25 : 09:24:51
|
| A bit of maths is required.start with getting todays dateextract the year portionassign this + 01/01 to a new field to make the start of the year...ie jan 1.take the integer (week no)multiply by 7add this number of days to jan 1 above.this get's you into the ball-park for your date selection....you will then need to set an upper/lower limit on the date to find the start/end of the week...play around with the numbers....and you should solve your problem.beaware that you may need to decide on what is 'the 1st day in a week'or what constitutes 'thge 1st valid week'...ie if week #1 begins on a friday....is it a "real working week"hth |
 |
|
|
|
|
|
|
|