Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

SET DATEFORMAT Not Working
I cannot get the following stored procedure to accept dates in the format
dd/mm/yyyy.

alter proc usp_test
 @FirstName	varchar(3
0),
 @DateOfBirth	datetim
e
AS
set dateformat dmy

INSERT INTO 	tbl_test (
Name,
DateOfBirth)
Values
( @FirstName, @DateOfBirth)
GO

exec usp_test 'Dan', '16/09/2005'
I am passing it a date such as '16/09/2005'.  Surely by using the Set
DATEFORMAT dmy this should work?
If I run the set dateformat dmy command in query analyser and then execute
the sp it works.  Any ideas??

Thanks

Report this thread to moderator Post Follow-up to this message
Old Post
dearle via webservertalk.com
09-29-05 06:23 PM


Re: SET DATEFORMAT Not Working
Dearle,

Try removing the SET DATEFORMAT dmy out of the proc and issuing it prior to
the EXEC.

HTH

Jerry
"dearle via webservertalk.com" <u14413@uwe> wrote in message
 news:5518d051f3812@u
we...
>I cannot get the following stored procedure to accept dates in the format
> dd/mm/yyyy.
>
> alter proc usp_test
> @FirstName varchar(30),
> @DateOfBirth datetime
> AS
> set dateformat dmy
>
> INSERT INTO tbl_test (
> Name,
> DateOfBirth)
> Values
> ( @FirstName, @DateOfBirth)
> GO
>
> exec usp_test 'Dan', '16/09/2005'
> I am passing it a date such as '16/09/2005'.  Surely by using the Set
> DATEFORMAT dmy this should work?
> If I run the set dateformat dmy command in query analyser and then execute
> the sp it works.  Any ideas??
>
> Thanks



Report this thread to moderator Post Follow-up to this message
Old Post
Jerry Spivey
09-29-05 06:23 PM


Re: SET DATEFORMAT Not Working
Hi,

Jerry Spivey is wright: "remove the SET DATEFORMAT dmy out of the proc"

I think you are calling the sp from an application... if this is the case
after you create the connection to the data base, you need to execute a
commando to the SQL "SET DATEFORMAT 'dmy'" from this point forward any sp yo
u
call from your program will have da date in the format 'dmy'

Joao

"Jerry Spivey" wrote:

> Dearle,
>
> Try removing the SET DATEFORMAT dmy out of the proc and issuing it prior t
o
> the EXEC.
>
> HTH
>
> Jerry
> "dearle via webservertalk.com" <u14413@uwe> wrote in message
>  news:5518d051f3812@u
we... 
>
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Joao Rego
09-29-05 06:23 PM


Re: SET DATEFORMAT Not Working
Previous posts are correct and here's why.

SETDATEFORMAT determines how to interpret character dates into a datetime
variable. This has already happened before the sproc is called and will
therefore have no effect on an already converted datetime value which is
being passed.

--
Nik Marshall-Blank MCSD/MCDBA

"Joao Rego" < JoaoRego@discussions
.microsoft.com> wrote in message
news:1E52552C-A519-4F3A-A911- 606FE5E589A2@microso
ft.com...
> Hi,
>
> Jerry Spivey is wright: "remove the SET DATEFORMAT dmy out of the proc"
>
> I think you are calling the sp from an application... if this is the case
> after you create the connection to the data base, you need to execute a
> commando to the SQL "SET DATEFORMAT 'dmy'" from this point forward any sp
> you
> call from your program will have da date in the format 'dmy'
>
> Joao
>
> "Jerry Spivey" wrote:
> 



Report this thread to moderator Post Follow-up to this message
Old Post
Nik Marshall-Blank \(delete fcom for my email addr
09-30-05 08:23 AM


Re: SET DATEFORMAT Not Working
Thanks for your help.  What determines the original dateformat?  Is there a
wao of changing this?


Jerry Spivey  wrote:[color=darkred
]
>Dearle,
>
>Try removing the SET DATEFORMAT dmy out of the proc and issuing it prior to
>the EXEC.
>
>HTH
>
>Jerry 
>[quoted text clipped - 19 lines] 


--
Message posted via webservertalk.com
http://www.webservertalk.com/Uwe/Fo...server/200509/1

Report this thread to moderator Post Follow-up to this message
Old Post
dearle via webservertalk.com
09-30-05 12:23 PM


Re: SET DATEFORMAT Not Working
The language of the login determines the dateformat of the connection. See s
p_helplanguage. Also, an
explicit SET DATEFORMAT or SET LANGUAGE will override the login's default. A
lways pass the datetime
in a safe format and you don't have to worry about this. Or, if you code ADO
 etc, define parameter
objects for each parameter and connect to a date variable in the host langua
ge and the API will
handle this for you. See http://www.karaszi.com/SQLServer/info_datetime.asp 
for more information.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www. solidqualitylearning
.com/
Blog: http:// solidqualitylearning
.com/blogs/tibor/


"dearle via webservertalk.com" <u14413@uwe> wrote in message  news:552127b0dca5d@u
we...[colo
r=darkred]
> Thanks for your help.  What determines the original dateformat?  Is there 
a
> wao of changing this?
>
>
> Jerry Spivey wrote: 
>
>
> --
> Message posted via webservertalk.com
> http://www.webservertalk.com/Uwe/Fo...server/200509/1[/color]


Report this thread to moderator Post Follow-up to this message
Old Post
Tibor Karaszi
09-30-05 12:23 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

MS SQL Server archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 02:38 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006