SQL Clone
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 Veteran
SSC Veteran (242 reputation)SSC Veteran (242 reputation)SSC Veteran (242 reputation)SSC Veteran (242 reputation)SSC Veteran (242 reputation)SSC Veteran (242 reputation)SSC Veteran (242 reputation)SSC Veteran (242 reputation)

Group: General Forum Members
Points: 242 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
Old Hand
Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)Old Hand (339 reputation)

Group: General Forum Members
Points: 339 Visits: 727
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
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4554 Visits: 1667
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
Right there with Babe
Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)

Group: General Forum Members
Points: 724 Visits: 256
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