dbTalk Databases Forums  

DateTime

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss DateTime in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
roblowein
 
Posts: n/a

Default DateTime - 06-19-2007 , 06:21 AM






Hello,

Please can you point me in the right direction.

I have a table (JobMain) that holds a list of all jobs that out
engineers need to work on or have worked on.

I would like to select jobs that fall between Monday - Friday 8am to
7pm.

The tables holds a load of colums ... the two that are of interest to
me are

JobId (Primary Key) - Job Number
StartDate (Datetime datatype) - Job start date and time

regards

Rob


Reply With Quote
  #2  
Old   
M A Srinivas
 
Posts: n/a

Default Re: DateTime - 06-19-2007 , 06:53 AM






On Jun 19, 4:21 pm, roblowein <rob.low... (AT) gmail (DOT) com> wrote:
Quote:
Hello,

Please can you point me in the right direction.

I have a table (JobMain) that holds a list of all jobs that out
engineers need to work on or have worked on.

I would like to select jobs that fall between Monday - Friday 8am to
7pm.

The tables holds a load of colums ... the two that are of interest to
me are

JobId (Primary Key) - Job Number
StartDate (Datetime datatype) - Job start date and time

regards

Rob
DECLARE @startdate datetime ,@enddate datetime

SET @startdate = '2007-06-18 08:00:00' -- Monday 8 AM
SET @enddate = DATEADD(DD,4 ,DATEADD(HOUR,11,@startdate)) --

SELECT @startdate,@enddate

SELECT * FROM yourtable
WHERE StartDate BETWEEN @startdate AND enddate



Reply With Quote
  #3  
Old   
Razvan Socol
 
Posts: n/a

Default Re: DateTime - 06-19-2007 , 06:56 AM



Hello, Rob

Try something like this:

SELECT * FROM YourTable
WHERE DATEPART(hh,StartDate) BETWEEN 8 AND 18
AND (DATEPART(w,StartDate)+@@DATEFIRST)%7 BETWEEN 2 AND 6

Razvan


Reply With Quote
  #4  
Old   
roblowein
 
Posts: n/a

Default Re: DateTime - 06-19-2007 , 08:45 AM



On 19 Jun, 12:56, Razvan Socol <rso... (AT) gmail (DOT) com> wrote:
Quote:
Hello, Rob

Try something like this:

SELECT * FROM YourTable
WHERE DATEPART(hh,StartDate) BETWEEN 8 AND 18
AND (DATEPART(w,StartDate)+@@DATEFIRST)%7 BETWEEN 2 AND 6

Razvan
Thanks to you both....

A lot of help..

Regards

Rob



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.