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
7.5.10
Where
7 is the day of the month
5 is the month
10 is the year
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)
select convert(varchar,cast(@date
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
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
ASKER
Oops....
7.5.10
7 is the YEAR
5 is the MONTH
10 is the DAY
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)
For example:
DECLARE @DT as varchar(15)
set @Dt = '7.5.10'
select CONVERT(datetime, @dt,4)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this:
SELECT CONVERT(VARCHAR(10), '7.5.10', 102) AS [YYYY.MM.DD]
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'
ASKER
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
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.