Year 2000 Checks | Database Journal

Year 2000 Checks

Written By
Alan Enderby
Alan Enderby
Oct 5, 2000
2 minute read

Want to know where dates are used in your database ?

This script
1)
Displays all tables containing columns with a datatype of datetime
or
smalldatetime
2) Displays all tables containing columns with a column name

containing (Year, month day…)
3) Shows stored procedures containing
Year, month day or any of the
date functions (datediff,dateadd ….)
4)
It can be modified to search for your own date user types

SET NOCOUNT
ON

declare @msg varchar(255)
Select @msg=’Days until Jan 1st 2000 = ‘
+
convert(varchar(5),Datediff(dd,getdate(),’1 jan 2000′))
print
@msg
select @msg=replicate(‘=’,datalength(@msg))
print @msg
print ‘

drop table #t1
go

create table #t1 (search_string
varchar(255))
Insert into #t1 values (‘%[ ]date%’)
Insert into #t1 values
(‘%day%’)
Insert into #t1 values (‘%Month%’)
Insert into #t1 values
(‘%Year%’)
Insert into #t1 values (‘%Week%’)
Insert into #t1 values
(‘%dateadd%’)
Insert into #t1 values (‘%datediff%’)
Insert into #t1 values
(‘%datepart%’)
Insert into #t1 values (‘%getdate()%’)

— Show tables
with columns or names containing date references

select distinct
‘Table’=o.name , ‘Column’= c.name , ‘Format’=
t.name
from sysobjects o ,
syscolumns c , systypes t ,#t1 m
Where o.id=c.id
and o.type=’U’
and
c.type=t.type
and (t.name like ‘%date%’
or patindex(search_string,c.name)
> 0)
order by o.name,c.name

print ‘ ‘

— Show stored
procedures containing date related words

select
search_string=substring(search_string,1,20),
‘SP
Name’=upper(o.name),
Seq=colid ,
‘SP
Line’=substring(text,patindex(search_string,text)-5, 30)
from syscomments c ,
sysobjects o , #t1 t
where o.id=c.id
and patindex(search_string,text) > 0
order by substring(search_string,1,20),name
go

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.