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
 getdate()

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2009-03-04 : 12:08:55
I want to update a field with getdate() but I do not want the time in the field even though the field is datetime. Is this possible?

update table
set date = getdate()

I want date to be 3/4/2009 and not 3/4/2009 00:00:00

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-04 : 12:14:10
update table
set date = DATEADD(Day, DATEDIFF(Day, 0, GetDate()), 0)


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

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-04 : 12:37:27
quote:
Originally posted by Vack

I want to update a field with getdate() but I do not want the time in the field even though the field is datetime. Is this possible?

update table
set date = getdate()

I want date to be 3/4/2009 and not 3/4/2009 00:00:00


you cant remove the time part altogether as sql server always stores time part along with date. However, the required formatting can be done at you front end application using date formatting functions to get date value alone
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-04 : 12:43:59
You can only remove the time portion if you use a char/varchar data type, but this is not recommended as you can't easily use date/time functions.

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

Subscribe to my blog
Go to Top of Page
   

- Advertisement -