Link to home
Start Free TrialLog in
Avatar of mattkovo
mattkovo

asked on

Convert to Date

I'm running Microsoft SQL Server 2008.  How can I convert this into a date?

7.5.10

Where
7 is the day of the month
5 is the month
10 is the year
Avatar of AmmarR
AmmarR
Flag of Bahrain image

select cast('7.5.10' as smalldatetime)
You don't say to what format but try this:
select convert(varchar,cast(@date as datetime),101)
to check that its working right

use Dateadd

select dateadd(d,4,cast('7.5.10' as smalldatetime))
this should add 4 days

select dateadd(m,2,cast('7.5.10' as smalldatetime))
this should add 4 months
Avatar of mattkovo
mattkovo

ASKER

Oops....

7.5.10

7 is the YEAR
5 is the MONTH
10 is the DAY
I think you'd just need to use the CONVERT keyword.  

For example:
DECLARE @DT as varchar(15)
set @Dt = '7.5.10'
select CONVERT(datetime, @dt,4)
ASKER CERTIFIED SOLUTION
Avatar of ChadFolden
ChadFolden

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this:

SELECT CONVERT(VARCHAR(10), '7.5.10', 102) AS [YYYY.MM.DD]
ignore my last post. The first one still works. Just replace @date with '7.5.10'
Avatar of Kumaraswamy R
Thanks!
mattkovo,

That is not "just another service" - a Cleanup Volunteer needs to act if you as asker don't. It is your task to care for your open questions.

Qlemo
Cleanup Volunteer
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.