Click here to Skip to main content
15,906,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello ,i want to Get Hours and Minutes (HH:MM) from time datatype in mssql
my table script is -
SQL
CREATE TABLE [dbo].[tbl_TimetablePeriod](
    [Period_Id] [int] IDENTITY(1,1) NOT NULL,
    [Period_Name] [nvarchar](100) NULL,
    [PeriodStarttime] [time](7) NULL,
    [PeriodEndtime] [time](7) NULL,
    [Created_At] [datetime] NULL,
    [Updated_At] [datetime] NULL,
 CONSTRAINT [PK_tbl_TimetablePeriod] PRIMARY KEY CLUSTERED
(
    [Period_Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

and stored procedure is-

SQL
CREATE PROCEDURE [dbo].[sp_GetAsignperiodforcreatetimetable]

as
select t.Period_Id,t.Period_Name,t.PeriodStarttime,t.PeriodEndtime from tbl_TimetablePeriod 



plz help me
Posted
Updated 23-Dec-13 19:28pm
v2

SQL
select t.Period_Id,t.Period_Name,
LTRIM(RIGHT(CONVERT(VARCHAR(20), t.PeriodStarttime, 100), 7)) AS PeriodStarttime,
LTRIM(RIGHT(CONVERT(VARCHAR(20), t.PeriodEndtime, 100), 7)) AS PeriodEndtime
from tbl_TimetablePeriod as t


MAY BE IT WILL HELP YOU

CSS
Period_Id   Period_Name PeriodStarttime PeriodEndtime
1            A           2:15AM          2:15AM
2            B           4:15AM          5:15AM
3            C           5:15PM          6:15PM
 
Share this answer
 
v3
Comments
manvendra patel 24-Dec-13 2:35am    
thankyou very much .
XML
The below query will get the current date in HH:MM:SS format.

<pre>select convert(varchar(25), getdate(), 108)</pre>

The following link has the complete list of convertions.

<a href="http://www.w3schools.com/sql/func_convert.asp">http://www.w3schools.com/sql/func_convert.asp</a>[<a href="http://www.w3schools.com/sql/func_convert.asp" target="_blank" title="New Window">^</a>]

Hope this helps.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900