Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Date Fields
Message
 
 
À
09/12/2004 14:07:14
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Divers
Thread ID:
00968070
Message ID:
00968215
Vues:
7
The code bellow shows how to drop a time part from a detetime value and how to check for dates that belong to a particular day. It could be be optimizable if there's an index on 'datefield'.
DECLARE @dt datetime
SET @dt = getdate()
-- Drop time part
-- 0 represents the base date (01/01/1900) in SQL Server
SET @dt = DATEADD(dd,DATEDIFF(dd,0,@dt),0)
SELECT ... 
	WHERE datefield >= @dt AND datefield < DATEADD(day, 1, @dt)
>My biggest beef in SQL Server is the lack of Date fields (without time).
>I am forever having to compare dates from '00:00' to '23:59' when the time is absolutely irrelavent.
>I thought of using a character field to store dates but then the date functions are more complicated and there is no date checking...
>Anyway, your comments are welcome.
>For now, can someone tell me the easiest way to compare a datetime field with multiple times throughout the day to a single date (any time of day)?
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform