Click here to Skip to main content
Click here to Skip to main content

Get Only DateTime Part without using Convert

, 10 Jun 2011
Rate this:
Please Sign up or sign in to vote.
This tip will enable you to get DateTime Part in SQL without using Convert
All of us know many techniques to get Datetime part in sql using Convert, but here I found something interesting which will work without using Convert.
Take a look
 
SELECT 
    CAST( FLOOR( CAST( getDate() AS FLOAT ) ) AS DATETIME )
or
select    CAST(
    (
     STR( YEAR( GETDATE() ) ) + '/' +
     STR( MONTH( GETDATE() ) ) + '/' +
     STR( DAY( GETDATE() ) )
     )
     AS DATETIME
     )
and
select Dateadd(dd,0,datediff(dd,0,getdate()))
 
Reference Link: Getting Only the Date Part of a Date/Time Stamp in SQL Server[^].

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

RaviRanjankr
Software Developer
India India
Microsoft Student Partner | CS Student | MCTS | CP MVP | Crazy Learner | Dreamer
 
An Indian, who loves his country, believes in freedom, He is an enthusiast Techie and crazy learner. He is passionate about Technologies and social media. He holds bachelor degree of CS in Information Technology and now pursuing Master degree in Computer Application.
 
He always excited and keen Interested in learning and sharing knowledge. He loves to write blog, learn new things, listen music, taking arts and Playing Games..
 
He keep himself on the desk of his imagination, hanging around with some inceptions.
Follow on   Twitter   Google+

Comments and Discussions

 
GeneralWhy do you need this workaround? What are the disadvantages ... PinmemberRaghu Karupakala10-Jun-11 5:19 
GeneralRe: There is not issues about performance,advantage and disadvan... PinmvpRaviRanjankr10-Jun-11 18:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 10 Jun 2011
Article Copyright 2011 by RaviRanjankr
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid