Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get the date part from a datetime field
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00909180
Message ID:
00909209
Vues:
15
This message has been marked as the solution to the initial question of the thread.
>is there an easier way to get the date part of a datetime field than using the year(), month() and date() funcitons ??


Hi Hans,

Try
DECLARE @dt datetime
SET @dt = getdate()
-- 0 represents the base date (01/01/1900) in SQL Server
SELECT DATEADD(dd,DATEDIFF(dd,0,@dt),0)
Or you can use CAST and CONVERT functions.
SELECT CAST(  CONVERT(char(10), getdate(),111) AS datetime)
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform