Home All Groups Group Topic Archive Search About

How can i change varchar to datetime

Author
26 Jun 2006 1:38 PM
basulasz
I have a datetime column in db that stores datetime in varchar format suct
that "20060616120621". I want to get this date in a datetime format to make
comparisions according to that. How can i do that with an SQL Query or c#
code?

Thanks

Author
26 Jun 2006 2:25 PM
Sanjib Biswas
You should call sql function to_date( string1, [ format_mask ], [
nls_language ] ) to convert a string to date format.

Show quote
"basulasz" <basul***@discussions.microsoft.com> wrote in message
news:B46EE007-5894-42FC-B46D-275CAEA907FF@microsoft.com...
>I have a datetime column in db that stores datetime in varchar format suct
> that "20060616120621". I want to get this date in a datetime format to
> make
> comparisions according to that. How can i do that with an SQL Query or c#
> code?
>
> Thanks
Author
26 Jun 2006 2:43 PM
pvdg42
"basulasz" <basul***@discussions.microsoft.com> wrote in message
news:B46EE007-5894-42FC-B46D-275CAEA907FF@microsoft.com...
>I have a datetime column in db that stores datetime in varchar format suct
> that "20060616120621". I want to get this date in a datetime format to
> make
> comparisions according to that. How can i do that with an SQL Query or c#
> code?
>
> Thanks

You don't indicate what kind of database you're using, but in Transact SQL
(for SQL Server), you can use CAST or CONVERT.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp
Author
27 Jun 2006 3:44 PM
cw
pvdg42 wrote:
Show quote
> "basulasz" <basul***@discussions.microsoft.com> wrote in message
> news:B46EE007-5894-42FC-B46D-275CAEA907FF@microsoft.com...
> >I have a datetime column in db that stores datetime in varchar format suct
> > that "20060616120621". I want to get this date in a datetime format to
> > make
> > comparisions according to that. How can i do that with an SQL Query or c#
> > code?
> >
> > Thanks
>
> You don't indicate what kind of database you're using, but in Transact SQL
> (for SQL Server), you can use CAST or CONVERT.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp

On the .NET side, if you want to convert, use
System.Convert.ToDateTime([date time string])

AddThis Social Bookmark Button