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 2008 Forums
 Transact-SQL (2008)
 prefix added to date filed

Author  Topic 

Blessed1978
Yak Posting Veteran

97 Posts

Posted - 2014-03-06 : 21:22:09
I would like to add 9999 to a column in my sql 2012 database named modified date which is in the format yyyy-mm-dd hh:mm:ss
so it should look like '9999-2013-02-01:23:00:000'

please advise

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-03-06 : 21:28:30
you mean update it back to the table ? what is the data type for that column ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Blessed1978
Yak Posting Veteran

97 Posts

Posted - 2014-03-06 : 22:16:13
the data type for modified date is datetime I just want to ad 9999-in front of the modified date 9999-modified_date
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-03-06 : 22:30:42
if you want to update the datetime value back in the table, that is not possible. It will be an invalid date.

if you are just want to show that during retrieving of the data, it is possible with
SELECT '9999-' + CONVERT(VARCHAR(30), modified_date, 121)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-03-06 : 22:32:25
quote:
Originally posted by Blessed1978

I would like to add 9999 to a column in my sql 2012 database named modified date which is in the format yyyy-mm-dd hh:mm:ss
so it should look like '9999-2013-02-01:23:00:000'

please advise



For you information, the datetime is not stored in the table in that format. It is stored in binary format. That is just how your query window present the date time to you


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -