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
 General SQL Server Forums
 New to SQL Server Programming
 Nvarchar(100) to date

Author  Topic 

Biz1705
Starting Member

8 Posts

Posted - 2010-10-05 : 02:58:34
Hi,

Currently in database I have nvarchar (100) which is 05/10/10 7:18:46 PM . I'm trying to convert nvarchar (100) back to date. Is there stored procedure to convert it?

Biz

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-05 : 04:06:54
You can use convert function.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-05 : 04:33:27
quote:
Originally posted by pk_bohra

You can use convert function.


Can you please show the convert-statement for this '05/10/10 7:18:46 PM'?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-05 : 04:52:23
quote:
Originally posted by webfred

quote:
Originally posted by pk_bohra

You can use convert function.


Can you please show the convert-statement for this '05/10/10 7:18:46 PM'?


No, you're never too old to Yak'n'Roll if you're too young to die.




Declare @Test nvarchar(100)
Set @Test = '05/10/10 7:18:46 PM'
Select convert(datetime,@Test,0)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-05 : 05:11:56
cool!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-10-05 : 06:04:17
quote:
Originally posted by pk_bohra

quote:
Originally posted by webfred

quote:
Originally posted by pk_bohra

You can use convert function.


Can you please show the convert-statement for this '05/10/10 7:18:46 PM'?


No, you're never too old to Yak'n'Roll if you're too young to die.




Declare @Test nvarchar(100)
Set @Test = '05/10/10 7:18:46 PM'
Select convert(datetime,@Test,0)



Beware that this depends on the local settings
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

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

Biz1705
Starting Member

8 Posts

Posted - 2010-10-05 : 18:05:38
Thank you for your reply madhivan.

I used Dbcc useroptions
got
language us_english
dateformat mdy

I am based in UK date system.
How can I convert nvarcha (100)to dd/mm/yyyy?

Biz
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-10-05 : 20:20:59
pk_bohra already showed you. also see this: http://msdn.microsoft.com/en-us/library/ms187928.aspx
Go to Top of Page

derrickbell23
Starting Member

1 Post

Posted - 2010-10-14 : 13:02:01
I have a a similar problem could anyone help me out.

I'm trying to convert a nvarchar(100) to a datetime data type.
The format currently is 05-16-2010 from what I have read looks like I would like to change it to a datetime style 5. I was trying to work with the above code, where do I set my column I would like converted?

Thanks for the help.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-14 : 13:10:08
declare @test nvarchar(100)
set @test='05-16-2010'
select
@test as Orig,
convert(datetime,@test,110) as Converted



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -