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 |
|
sbt1
Yak Posting Veteran
89 Posts |
Posted - 2004-02-02 : 11:21:17
|
| I have an application which stores tasks including dates. The dates are (naturally) using a regular date type field.I need to be able to have users schedule things like "Every Friday" or "Monday-Friday" (similar to how Outlook does it).Is there support for this type of thing in SQL Server? If I create a table of these "named dates" (for lack of a better name) my scheduling app can reference them... but how do I do a query to find the actual dates which make up "Every Friday" (up until a certain date so it doesn't go on endlessly) |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2004-02-02 : 11:42:31
|
| You could use the dw option in datepart. For example to query all Fridays in a date range in a table you would do something likeSELECT * FROM tablename WHERE DATEPART(dw, DateColumn) = 6Raymond |
 |
|
|
sbt1
Yak Posting Veteran
89 Posts |
Posted - 2004-02-03 : 09:27:50
|
| Can I run a query to return the date value (as a date type) representing, for example, dates where the dw value is 6 and the date is after 01/01/2004 and before 06/01/2004? |
 |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2004-02-03 : 09:34:30
|
| Probably not in a single command, but I'd do something like this in SQL2000:DECLARE @DatesTable TABLE (TheDate DATETIME)DECLARE @TempDate DATETIME, @Start DATETIME, @End DATETIMESELECT @Start = '20040101', @End = '20040601', @TempDate = @StartWHILE @TempDate <= @EndBEGIN INSERT INTO @DatesTable VALUES (@TempDate) SELECT @TempDate = DATEADD(dd, 1, @TempDate)ENDSELECT * FROM @DatesTable WHERE DATEPART(dw, TheDate) = 6Raymond |
 |
|
|
|
|
|