User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 456,531 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,890 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 1039 | Replies: 1
Reply
Join Date: Oct 2007
Posts: 1
Reputation: PKG is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
PKG PKG is offline Offline
Newbie Poster

datetime decrement

  #1  
Oct 6th, 2007
I have a VB program that needs to count number of events between two datetime values.

Something like this:

SELECT COUNT(*) FROM Report WHERE WeigthTime BETWEEN "Time1" AND "Time2"

Time1 is now. I get it with "SELECT GETDATE()"

I need to calculate Time2 by decrementing it for X hours. X is insertred in VB Form.

Is there some operators for datetime format?

Please help.
Best regards
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Posts: 1
Reputation: j_kelly is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
j_kelly j_kelly is offline Offline
Newbie Poster

Re: datetime decrement

  #2  
Oct 8th, 2007
Hi,

To decrement a datetime by a number of hours you can use the DATEADD function. Rather than using a positive number ,which would increment datetime, use a negative number.

http://technet.microsoft.com/en-us/l.../ms186819.aspx

Hope that helps.

James
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 4:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC