Search:
Locator+ Code:
FTPOnline Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Back to VSLive! Show Daily Home

Calculate the Current Day
Use this simple and efficient code to find the current day.

by Michel Ulens

VSLive! SF, Day 2, February 13, 2002 — Need to calculate the current day, without the time? Michel Ulens, presenting a session on "Working Better With Linked Servers," has a simple and efficient piece of code you can use:

--calculate TODAY, in SQL2000
declare @Today datetime, @T datetime
select @t = Getdate() - 0.78
select @Today = convert(datetime, convert(
   int, @T + 0.5)) - 1
select @Today Today, @T Now

select @t = Getdate() - 0.3
select @Today = convert(datetime, convert(
   int, @T + 0.5)) - 1
select @Today Today, @T Now

select @t = Getdate()
select @Today = convert(datetime, convert(
   int, @T + 0.5)) - 1
select @Today Today, @T Now

select @t = Getdate() + 0.3
select @Today = convert(datetime, convert(
   int, @T + 0.5)) - 1
select @Today Today, @T Now

select @t = Getdate() + 0.78
select @Today = convert(datetime, convert(
   int, @T + 0.5)) - 1
select @Today Today, @T Now 

About the Author
Michel Ulens has spent the past two years working as an independent consultant on various projects using SQL Server 7 and Oracle 7.x on a daily basis. Before that, Michel worked for five years for a European food manufacturer and was responsible for the development of planning software.

Back to top




Java Pro | .NET Magazine | Visual Studio Magazine | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home