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 2005 Forums
 Transact-SQL (2005)
 in query format to date

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-10-12 : 04:50:16
i have a nvarchar filed that has dates in the format of

day-month-year

where today would be 12-10-2007
but Feb 8 ,2007 would be 8-2-2007 (just on character)

can I convert this to an sql date when retrieving my query?
can anyone help me with this?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-12 : 04:58:37
1 Always use proper DATETIME datatype to store dates
2 It is your front end application where you should do the formation there
3 Read about convert function in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-10-12 : 04:59:52
You should add a column which has a DateTime datatype, or convert that column to DateTime.

You can convert the dates from String to DATETIME datatype (and provide a "day-month-year" hint), and then you can convert them to whatever format you want - preferably using your front end application rather than doing that conversion on the Server

SELECT CONVERT(Datetime, MyDate, 104)
FROM
(
SELECT [MyDate] = '12-10-2007' UNION ALL
SELECT [MyDate] = '8-2-2007'
) AS X

Kristen
Go to Top of Page
   

- Advertisement -