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 2005 Forums
 Transact-SQL (2005)
 Date Conversion

Author  Topic 

mmfarmani
Starting Member

22 Posts

Posted - 2007-07-12 : 13:01:51
Hello,
I need to select records in the database which 15 days have been passed from their creation date... Means they are older than 15 days! It sounds easy but I have problem converting the date to calculate days…

Thanks

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-12 : 13:04:26
where yourDateColumn < dateadd(d, -15, getdate())

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-07-12 : 13:05:39
where crdate < convert(varchar(8),getdate() - 15,112)
where datediff(dd,crdate,getdate()) > 15


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-13 : 00:14:57
quote:
Originally posted by spirit1

where yourDateColumn < dateadd(d, -15, getdate())

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp


I think you need to omit Time as well
where yourDateColumn dateadd(d, -15, datediff(day,0,getdate()))

Madhivanan

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

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-13 : 03:51:28
i'm leaving that as an excercise to the user

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-13 : 08:18:55
quote:
Originally posted by spirit1

i'm leaving that as an excercise to the user

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp


Well said

Madhivanan

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

- Advertisement -