Link to home
Start Free TrialLog in
Avatar of dsoderstrom
dsoderstrom

asked on

Extracting time as a string from datetime field

I am writing a query to pull data from one table and write it to another in SQL Server 2008.
On one datetime field in the first table I want to write only the time portion to the second table as nvarchar(8) data.
For example, the field in the first table contains "1/1/1900 1:41:33 PM".  I want to write it to the second table as "13:41:33".
Can someone show me how to do this?
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dsoderstrom
dsoderstrom

ASKER

Perfect.  Thank You.
You are still depending on system defaults for the format with that approach, this stipulates hh:mm:ss

         select  convert(varchar(8), GETDATE(),108)

see: SQL Server Date Styles (formats) using CONVERT()
e.g. if you needed milliseconds use style 114