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
 update datetime field

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2011-04-19 : 14:34:01
I'm trying to update a datetime field.

the field datum has a value of 2011-03-21 00:00:00:000

When I try this:

update gbkmut
set datum = 2011-04-01

It updates the field with 1905-03-06 00:00:00:000

If I try:
update gbkmut
set datum = 4/01/2011

It updates the field with 1900-01-01

How do I update this field to get the correct data in it?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-19 : 14:37:18
update gbkmut
set datum = '2011-04-01'

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

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-19 : 14:38:13
Without the single quotes, you are actually doing math: 4 divided by 1 divided by 2011.

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

Subscribe to my blog
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2011-04-19 : 14:39:54
Enclose the date in single quotes, and use the universal YYYYMMDD format.

update gbkmut
set datum = '20110401'


CODO ERGO SUM
Go to Top of Page
   

- Advertisement -