Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Get DATE part of the DATETIME


Get DATE part of the DATETIME

Author
Message
jreece
jreece
SSC Rookie
SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)

Group: General Forum Members
Points: 34 Visits: 132
I was using Method 4, saw this post and was an immediate convert to Method 1 till I saw Method 3, the simplest yet, and as it turns out, the fastest!
But nothing beats the simplicity of TRUNC(sysdate) - a PL/SQL function I really miss.
guoa
guoa
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 326
0.25 should be 6AM, right? Not 4AM.
Dave Vroman
Dave Vroman
SSC-Enthusiastic
SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)

Group: General Forum Members
Points: 163 Visits: 715
Our inhouse method of doing this for today's date is:
DATEDIFF(d, 0, GETDATE())
or for a general date from the DB:
DATEDIFF(d, 0, DateField)

DATEDIFF may be more expensive, but is it more expensive than "CAST(FLOOR(CAST("?
YSLGuru
YSLGuru
SSC Eights!
SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)SSC Eights! (959 reputation)

Group: General Forum Members
Points: 959 Visits: 1659
For what its worth.... from my 'T-SQL Shortcuts' scripts I found the following:

/*Per SQL GURU Itzah-Ben Gah the fastest way to extract the date portion of a DateTime value is:*/
SELECT CONVERT(DATETIME,Floor(Convert(FLOAT, GetDate() ) ) )




I don't recall if Itzah was referring to a SQL Serve 2XXX specific platform or T-SQL in general and I did not note anything about specific SQL versions along with this shortcut.

Kindest Regards,

Just say No to Facebook!
wodom
wodom
SSC-Enthusiastic
SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)SSC-Enthusiastic (146 reputation)

Group: General Forum Members
Points: 146 Visits: 255
Am I the only one who noticed this error in the original article?

> with right section of the decimal point representing
> number of dates since 01-Jan-1900

"right section of the decimal point" should read either "left of the decimal point" or "whole number portion."



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search