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 |
iordanissav
Starting Member
4 Posts |
Posted - 2007-09-20 : 20:31:58
|
I'm creating a betting system and my question follows:how can i create a function to return the current date in my country, when the server is hosted for free in another country with a time difference?So far i created the following: ----------------------------------- -- created the procedure because -- I can't use GETDATE()/GETUTCDATE() inside a function -- read the help file ----------------------------------- CREATE PROCEDURE usp_CurrentDateTime(@ai_hours_to_add int, @current_date_time datetime output) AS -- could use GETUTCDATE() also select @current_date_time = dateadd(hh, @ai_hours_to_add, GETDATE()) ---------------------------------- -- created the function f_cdt (CurrentDateTime) -- to use as a scalar one, in several places -- of my code ---------------------------------- CREATE FUNCTION f_cdt(@hours_to_add smallint) RETURNS datetime AS BEGIN declare @dt datetime exec usp_CurrentDateTime @hours_to_add, @dt return @dt END ------- When I use the function : select dbo.f_cdt(3) I get the following message in Query Analyzer: Server: Msg 557, Level 16, State 2, Procedure f_cdt , Line 6 Only functions and extended stored procedures can be executed from within a function. |
|
Kristen
Test
22859 Posts |
Posted - 2007-09-20 : 20:33:56
|
"I can't use GETDATE()/GETUTCDATE() inside a function"We pass GetDate() into the function, as a parameter, when we need a function to make use of current date/timeKristen |
 |
|
|
|
|