从mssql中的time数据类型获取小时和分钟(HH:MM) [英] Get Hours and Minutes (HH:MM) from time datatype in mssql

查看:648
本文介绍了从mssql中的time数据类型获取小时和分钟(HH:MM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想从mssql中的时间数据类型获取小时和分钟(HH:MM)

我的表脚本是 -

hello ,i want to Get Hours and Minutes (HH:MM) from time datatype in mssql
my table script is -

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-

CREATE PROCEDURE [dbo].[sp_GetAsignperiodforcreatetimetable]

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



< br $> b $ b

plz帮我




plz help me

推荐答案

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




Period_Id   Period_Name PeriodStarttime PeriodEndtime
1            A           2:15AM          2:15AM
2            B           4:15AM          5:15AM
3            C           5:15PM          6:15PM


阅读以下内容: http://blog.sqlauthority.com/2009/08/06/sql-server-get-time-in-hourminute-format-from-a-datetime-get-date-part-only-from -datetime / [ ^ ]
Read the following : http://blog.sqlauthority.com/2009/08/06/sql-server-get-time-in-hourminute-format-from-a-datetime-get-date-part-only-from-datetime/[^]


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.


这篇关于从mssql中的time数据类型获取小时和分钟(HH:MM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆