MS SQL Tips & Tricks

How to get date part of datetime value

Very common problem is how to get date part of DATETIME column. The simplest way is: You can also use one of this methods:

First method

declare @cDateTime datetime;

set @cDateTime = GetDate()

select dateadd(dd,0, datediff(dd,0,@cDateTime))

... and the second

declare @cDateTime datetime;

set @cDateTime = GetDate()

select	(CAST(	
	CEILING( 
		CAST( 
			CAST(@cDateTime AS DATETIME) AS float
			)
		)AS DATETIME)-
	(CEILING( 
		CAST( 
			CAST(@cDateTime AS DATETIME) AS float
			)
		)
	- FLOOR( 
	CAST( 
		CAST(@cDateTime AS DATETIME)as float
		)
	)
)
Download SQL script

Learn more tricks

Add Comment

Comments

27th August 2021

https://buytadalafshop.com/ - Cialis

ceagods

31st August 2021

Propecia Itch Scabies Medication

Stromectol

4th September 2021

Cialas Professional For Sale

best place to buy finasteride

8th September 2021

Want to buy isotretinoin free doctor consultation

cialis vs viagra levitra

8th September 2021

Propecia

Gursefs

14th September 2021

Lasix

Huncalm

14th September 2021

http://buyzithromaxinf.com/ - zithromax liquid

Knillosse

16th September 2021

Viagra Ou Acheter Forum

Plaquenil