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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetDate() plus 1 hour 1

Status
Not open for further replies.

aaronjonmartin

Technical User
Jul 9, 2002
475
GB
Hi guys hope you can help me with this one.

I am using GetDate() in one of my stored procedures, but I need to add one hour onto whatever date/time GetDate() returns. How can I do this?

Thanks for any help in advance.

"It's so much easier to suggest solutions when you don't know too much about the problem."
Malcolm Forbes (1919 - 1990)
 
Thanks for the help r937, I actually made a mistake in my first post, I needed to subtract an hour. But I changed your code to dateadd(hh,-1,getdate()) and that works fine.

Im still having a problem with the query im using it in though. Maybe I should make a new post but Ill put it here anyway.

Basically I need to compare two date/times and as long as the current date/time (albeit minus an hour) is earlier than a set date/time then insert some values into a table. But its not working, here is my code:

Code:
CREATE procedure SPinsertPrediction
@UserID int,
@GameID int,
@Pred1 char(2),
@Pred2 char(2), 
@Pred3 char(2),
@Pred4 char(2),
@Pred5 char(2),
@Pred6 char(2),
@NumGoals int,
@kotime datetime

AS

DECLARE @datreturned int

IF @kotime > dateadd(hh,-1,getdate())
INSERT INTO Predictions (UserID, GameID, Pred1, Pred2, Pred3, Pred4, Pred5, Pred6, NumGoals)
VALUES (@UserID, @GameID, @Pred1, @Pred2, @Pred3, @Pred4, @Pred5, @Pred6, @NumGoals)
SELECT scope_identity() AS 'PredID'

In this example @kotime equals 02.08.2007 15:00:00 and for example the current date time equals 02.08.2007 11:43:16 then the values should be inserted. But my procedure doesnt seem to be inserting them. Does the way I have tried to do it in the above stored procedure only compare the dates and not the times and this is why im having the problem?

Thanks again for your help



"It's so much easier to suggest solutions when you don't know too much about the problem."
Malcolm Forbes (1919 - 1990)
 
Ive figured it out. It was my mistake, the two dates I was comparing are in different formate i.e. dd/mm/yyyy hh:mm:ss and mm/dd/yyyy hh:mm:ss.

All sorted now. Thanks again for your help

"It's so much easier to suggest solutions when you don't know too much about the problem."
Malcolm Forbes (1919 - 1990)
 
Why are date columns being stored as text? Change them to datetime.

[COLOR=black #d0d0d0]When I walk, I sometimes bump into things. I am closing my eyes so that the room will be empty.[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top