Avatar of Varshini S
Varshini S
 asked on

What is the best way to handle SQL Server date collation ?

I am using the below SQL date format ('Dec 31 2015')  in my SQL SP across the board.

Select name,age,salary from employee where RecordDate='Dec 31 2015'

Will it be an issue if the SQL collation change ?
 In that case, what is the SQL date format (to support any collation)  i can use in my SP ?
Microsoft SQL Server 2008Microsoft SQL Server

Avatar of undefined
Last Comment
Vitor Montalvão

8/22/2022 - Mon
Peter Chan

Actually DB collation is not affecting date format. But still you can try this
...where CONVERT(varchar,RecordDate,109)='Dec 31 2015'

Open in new window

ste5an

It's better to use a nonambiguous format for your literals. Yours depends on language and order (SET DATEFORMAT).

The most common format is YYYY-MM-DD. It's also the ISO 8601 standard, which is the only international date format.

The second neutral format is the ODBC format: { d 'yyyy-mm-dd' }  

See also Supported String Literal Formats for date.
PortletPaul

there are 2 "safe" date literals in SQL Server

YYYYMMDD
YYYY-MM-DDThh:mm:ss[.nnn]

           nb: YYYY-MM-DD by itself is NOT 100% safe also see: Bad habits to kick : mis-handling date / range queries

NEVER use a language dependent literal that depends on the name of a month

Select name, age, salary from employee where RecordDate = '20151231' --YYYYMMDD is safe
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Olaf Doschke

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Vitor Montalvão

Varshini, do you still need help with this question?