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 2000 Forums
 SQL Server Development (2000)
 Date field need to be updated...

Author  Topic 

Prajwal
Starting Member

6 Posts

Posted - 2005-06-29 : 19:51:59
I have a date field in the table which has different values for all the different rows.

I need a query to update the century from '19' to '20' in all the rows.

The format is yyyy-mm-dd

Example: The current date in the table is 1935-06-29...After I run the query,it should become 2035-06-29...

Can someone please help!!!

Thanks!!!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-06-29 : 19:55:16
Make sure this is correct before running the UPDATE:
SELECT DATEADD(yy, 100, YourColumn) AS YourColumn
FROM YourTable

The update:
UPDATE YourTable
SET YourColumn = DATEADD(yy, 100, YourColumn)

Tara
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2005-06-29 : 20:10:47
WHERE Year(YourColumn) < 2000

HTH

=================================================================
'Tis with our judgements as our watches: none Go just alike, yet each believes his own. -Alexander Pope, poet (1688-1744)
Go to Top of Page

Prajwal
Starting Member

6 Posts

Posted - 2005-06-29 : 22:52:01
Thanks for your replies...

Thanks tduggan... but Dateadd wasn't recognized...

Thanks Bustaz Kool...But,

The values are different in each row...So, I can't update the same value...

Wherever there is 19, it needs to change to 20

Exaple:

1935 needs to change to 2035
1946 needs to change to 2046

............................
............................

etc...

any more help ...please...

Thanks!!!
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-06-29 : 23:40:16
Is your date field char or varchar? If so, then:

UPDATE YourTable
SET YourDateColumn = STUFF(YourDateColumn, 1, 2, '20')
WHERE LEFT(YourDateColumn, 2) = '19'
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-06-30 : 07:20:31
what do you mean dateadd was not recognized?

is this mssql or access?

--------------------
keeping it simple...
Go to Top of Page

Prajwal
Starting Member

6 Posts

Posted - 2005-06-30 : 15:58:25
DATEADD worked...

Thanks for your help 'tduggan' and other guys!!!
Go to Top of Page
   

- Advertisement -