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.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Passing universal Date format.

Author  Topic 

slihp
Yak Posting Veteran

61 Posts

Posted - 2014-05-01 : 11:58:58
In my previous job i started all my stored procs that passed in date variables with

SET DATEFORMAT DMY

as i was UK based it was just a bad habit i got into to ensure regional settings never interfered with my results.

Im now in a new position where ill be writing stored procs that will have the potential to be run globally, so id like to write them in such as way as any dates passed i don't need to worry about the regional settings sql is on.

im aware of a few ways to do this but would like to ask the question and get expert confirmations.

Thanks

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-05-01 : 12:16:12
My suggestion would be to always use an ANSI or ISO date format for date strings (unambiguous):
yyyy-mm-ddThh:mi:ss.mmm (no spaces) - ISO8601
yyyy-mm-ddThh:mi:ss.mmmZ (no spaces) - ISO8601 with time zone Z.
yymmdd OR yyyymmdd - ISO
But, if you are writing sprocs, then you should, hopefully, be using the proper data types, so format doesn't really have an affect there.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-05-09 : 05:48:47
make sure you read this

http://visakhm.blogspot.in/2011/12/why-iso-format-is-recommended-while.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -