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
 replace a column with a date format

Author  Topic 

jasonsy
Starting Member

11 Posts

Posted - 2010-03-11 : 00:38:31
How can i change my column that is a date format with for example

2010-01-08 00:00:00.000

thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-11 : 00:39:37
If your column is datetime data type, then you can not change the format that it gets saved as. You can change the format when you retrieve it out of the database using the CONVERT function and the appropriate style, but it's better to do the formatting in your application rather than T-SQL since it's a presentation layer issue.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

jasonsy
Starting Member

11 Posts

Posted - 2010-03-11 : 00:48:30
I really need this value for my date because my program will not run if that's not the value. My column is null. is it possible to have a datetime format with this value 2010-01-08 00:00:00.000?

thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-11 : 02:17:31
quote:
Originally posted by jasonsy

I really need this value for my date because my program will not run if that's not the value. My column is null. is it possible to have a datetime format with this value 2010-01-08 00:00:00.000?

thanks


What is the datatype of the date column?
If the column is NULL, is there a reason to update it with 2010-01-08 00:00:00.000?


Madhivanan

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

jasonsy
Starting Member

11 Posts

Posted - 2010-03-11 : 02:23:43
datetime. yup the date should be the current date but the time it must be 00:00:00.000. is it possible?

Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2010-03-11 : 02:28:05
use this

select dateadd(d,datediff(d,0,getdate()),0)
Go to Top of Page

jasonsy
Starting Member

11 Posts

Posted - 2010-03-11 : 02:35:24
many thanks!
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2010-03-11 : 05:27:44
quote:
Originally posted by jasonsy

many thanks!



Welcome...
Go to Top of Page
   

- Advertisement -