Share via


Convert timestamp to varchar

Question

Friday, February 15, 2013 10:11 AM

Hi Floks,

   Is This Possible To convert Timestamp into varchar in SQLSERVER.

Plaease help as soon as possible.

I am already tried with this queries

create table timestamp1 (
ID int identity(1, 1) primary key
, ts timestamp NOT NULL
)

alter table timestamp1
alter column ts varbinary(8)

alter table timestamp1
alter column ts varchar(8) 

Thanks

siva

All replies (4)

Friday, February 15, 2013 10:35 AM ✅Answered | 1 vote

No you cannot.

You can add new column as varchar and update the new column with the proper values and then drop the time-stamp column

Or

Just do the conversion while retrieving the records using Cast or Convert

Satheesh


Friday, February 15, 2013 10:50 AM ✅Answered | 1 vote

You can not use Varchar, use varbinary.

create table timestamp1 (ID int identity(1, 1) primary key, ts timestamp NOT NULL,name Varchar(50))Insert Into timestamp1(name) Select 'Latheesh'Select *,CAST(ts as varbinary(MAX)),CAST(ts as varchar(MAX)) From timestamp1Drop table timestamp1

Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.


Friday, February 15, 2013 10:30 AM

You can't ALTER TIMESTAMP DATATYPE. You could drop it and recreate it though.

http://msdn.microsoft.com/en-us/library/ms190273(v=sql.100).aspx

The modified column cannot be any one of the following:
A column with a timestamp data type.

Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.


Friday, February 15, 2013 10:42 AM

Hi Satheesh,

  yes i am agree with you. i had tried with this code

declare @hexbin varbinary(max);
set @hexbin = 0xabcedf012439;
insert into table1 select CONVERT(varchar(max), @hexbin, 1);

finally the destination table(table1) having varchar datatype with the related column

regards

Siva