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)
 Need Help in converting text format to datetime

Author  Topic 

venu256
Starting Member

2 Posts

Posted - 2008-11-06 : 12:06:27
Hi,

My Input data is in the format of 2001/12 (Character data type) I want it in datetime format?

Is there any way that I can covert that character to datetime format?

I've tried both Cast and Convert functions but it is not helping me out..Is there any way that I can get the output?

Its very Urgent..

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-11-06 : 12:09:58
what day part would you want there ?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-06 : 12:10:04
Try
SELECT cast(yourcol+'/01' AS datetime) FROM Table
Go to Top of Page

venu256
Starting Member

2 Posts

Posted - 2008-11-06 : 12:58:32
Thank You Very Much.....Its working
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-07 : 01:17:08
quote:
Originally posted by venu256

Hi,

My Input data is in the format of 2001/12 (Character data type) I want it in datetime format?

Is there any way that I can covert that character to datetime format?

I've tried both Cast and Convert functions but it is not helping me out..Is there any way that I can get the output?

Its very Urgent..


Do you want to get the date december 01, 2001 for 2001/12?
If so, use
SELECT cast(replace(your_col,'/','')+'01' AS datetime) from your_table


Madhivanan

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

- Advertisement -