Answered by:
get pure date and time from a date time value

Question
-
I have pure date and pure time fields in my SQL Server 2008 database server.
My procedure receives datetime data from the client.
I need to parse the datetime value to date and time to store in my table.
I can use datepart to get yyyy-mm-dd hh:mm:ss and convert to time or date value.
I would like to know are there any function can get pure date and pure time from datetime value from client applications.
Your help and information is great appreciated,
Regards,
Souris,
Tuesday, September 10, 2013 2:26 PM
Answers
-
SELECT CONVERT(DATE, GETDATE()) AS JustDate , CONVERT(TIME, GETDATE()) AS JustTime
The most important motivation for the research work that resulted in the relational model was the objective of providing a sharp and clear boundary between the logical and physical aspects of database management. - E. F. Codd
Saeid Hasani's home page- Proposed as answer by Allen Li - MSFT Thursday, September 12, 2013 7:03 AM
- Marked as answer by sourises Sunday, September 15, 2013 4:18 AM
Tuesday, September 10, 2013 2:30 PM
All replies
-
SELECT CONVERT(DATE, GETDATE()) AS JustDate , CONVERT(TIME, GETDATE()) AS JustTime
The most important motivation for the research work that resulted in the relational model was the objective of providing a sharp and clear boundary between the logical and physical aspects of database management. - E. F. Codd
Saeid Hasani's home page- Proposed as answer by Allen Li - MSFT Thursday, September 12, 2013 7:03 AM
- Marked as answer by sourises Sunday, September 15, 2013 4:18 AM
Tuesday, September 10, 2013 2:30 PM -
I don't know what you mean by pure date and pure time, you date part and time part
SELECT CAST(GETDATE() AS DATE)dateonly, CAST(GETDATE() AS TIME)timeOnly
vt
Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker
Tuesday, September 10, 2013 2:30 PM -
SELECT CONVERT(char(10), GETDATE(),101) AS JustDate , CONVERT(char(8), GETDATE(),108) AS JustTime
Regards, RSingh
Tuesday, September 10, 2013 2:47 PM -
You will be sorry with the approach of having a seperate date and time fields. You will be constantly adding them back together. Time has no meaning without a date. I would suggest rethinking this design.
- Proposed as answer by Kalman Toth Tuesday, September 10, 2013 4:22 PM
Tuesday, September 10, 2013 3:12 PM -
The datepart is doesn't really needed.
SQL server has both date and time datatypes.
Simply cast,
Declare @datetimevalue datetime=Current_timestamp select CAST(@datetimevalue as Date)[date only part], CAST(@datetimevalue as time) [Time only part]
instead of separating and storing in different columns, store as datetime and while retrieving/presenting do the conversion/separation.
Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.
Tuesday, September 10, 2013 3:25 PM