How to get a time and Date Separately?
sql-server
Solution
You can retrieve separate date and time parts like:
SELECT
CONVERT(VARCHAR(10),DateField,101) as DatePart,
CONVERT(VARCHAR(10),DateField,108) as TimePart
FROM YourTable
For more information, see the CONVERT documentation.
The code snippet above returns the DataPart and TimePart as a varchar. If you're interested in retrieving them as a datetime field, try:
SELECT
DATEADD(D, 0, DATEDIFF(D, 0, DateField)) as DatePart,
DATEADD(day, -DATEDIFF(D, 0, DateField), DateField) as TimePart
FROM YourTable
Problem
Using SQL Server 2005 Table1 Time ``` 12/05/2009 08:30:49 12/05/2009 17:00:00 13/05/2009 21:00:00 ``` ..., Above Table Both values are same column, Here I want to separate column like Date and Time Expected Output ``` Date Time 12/05/2009 08:30:49 12/05/2009 17:00:00 13/05/2009 21:00:00 ```