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
 Date Time

Author  Topic 

honeytjames
Starting Member

3 Posts

Posted - 2008-10-19 : 21:42:43
I have a column of datetime type. How do i insert a value less than getdate()?

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-19 : 22:05:09
insert into yourtable (todaysdate) select getdate() -1 -- gives you yersterday's date

Or add the getdate() - 1 to the default values
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-19 : 22:23:34
Also bear in mind, you can get different hours based on fractions of 1/24 (Which is 0.04166666666 and will give you 1 hour)

So to get the time, an hour back or an hour ahead you can use

select getdate()
select getdate() +0.04166666666666666666666
select getdate() -0.04166666666666666666666
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-19 : 23:43:03
or use DATEADD function. use negative number to add like
DATEADD(dd,-3,GETDATE())...
Go to Top of Page
   

- Advertisement -