in

vbCity Blogs

New (temp) place for vbCity Blogs

Mike McIntyre's .NET Journal

MS SQL Server Date without Time Solution for MS SQL Server versions 2005 and 2000

SQL Server versions prior to 2008 did not provide Date and Time data types. 

Below is a solution for SQL Server 2005 and 2000 that will strip time off a DateTime data type value.

SELECT DATEADD(DAY,DATEDIFF(DAY,0,[DateTime]),0)

 

Example Use

 

-- Create a variable of type DATETIME and store a date and time it it.

DECLARE @DateWithTime DATETIME

DECLARE @DateWithoutTime DATETIME

 

-- Store a date with time in the @DateWithTime variable.

SET @DateWithTime = GETDATE()

 

-- See date and time:

SELECT @DateWithTime

 

-- Use the solution to store only the date in the @DateWithoutTime variable.

SET @DateWithoutTime = DATEADD(DAY,DATEDIFF(DAY,0,@DateWithTime),0)

 

-- See date without time:

SELECT @DateWithoutTime

 

Only published comments... Jan 27 2009, 07:44 AM by Mike McIntyre
Filed under: , , ,

About Mike McIntyre

I  am a programmer, developer, and system architect with 29+years experience including state-of-the-art application development frameworks and languages including Visual Studio 2008, .NET 3.5, C#, and Visual Basic.

I am a mentor, trainer, and coach in the Microsoft .NET technical community. DevCity is my favorite community site. You can find examples of my involvement with DevCity in the site articles, newsletter articles, and my posts in the forum.

Since 2002 I have hosted a .NET site at http://www.getdotnetcode.com, a place with free and inexpensive Visual Basic and C# source code that can be purchased on an 'as needed' basis.

In 2007 I established a .NET search engine, 'Resources for .NET Developers' at http://dot-net-resources-swicki.eurekster.com

Copyright 1998-2009 vbCity.com LLC
Powered by Community Server (Non-Commercial Edition), by Telligent Systems