本文介绍了我在MS SQL中为hh:mm tt保存了什么数据类型sholuld的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页表单,其中包含hh:mm tt的下拉列表,间隔时间为30分钟,从上午6:00,上午6:30,上午7:00 ......晚上8:00开始。如何将选定的时间保存到MS Sql。我不确定Microsoft SQL中我应该使用什么数据类型(Date,DateTime,Time(7)。请帮我指教。这是我的c#代码来定义hh:mm tt并在表单上加载。



I have a web form that has a dropdownlist with hh:mm tt with 30 minutes interval, starting from 6:00am, 6:30 am, 7:00am....8:00pm. How can I save selected time to MS Sql. I am not sure what datatype (Date, DateTime, Time(7) in Microsoft SQL I should use. Please help me advise. This is my c# code to define hh:mm tt and load on the form.

private void AddDropDownValues(ref DropDownList ddlHrMin, int startHour, int endHour, int increment)
   {
       DateTime now = DateTime.Now;
       DateTime startTime = new DateTime(now.Year, now.Month, now.Day, startHour, 0, 0);
       DateTime endTime = new DateTime(now.Year, now.Month, now.Day, endHour, 0, 0);

       while (startTime <= endTime)
       {
           ddlHrMin.Items.Add(startTime.ToShortTimeString());
           startTime = startTime.AddMinutes(increment);
       }
   }







protected void Page_Load(object sender, EventArgs e)
  {

      AddDropDownValues(ref ddlHrMin, 6, 20, 30);

  }

推荐答案

USE Master

CREATE table #t1(TT time)
Insert INTO #t1 VALUES(getdate())
SELECT * FROM #t1
Drop table #t1


Quote:

您可以使用时间数据类型来存储类型

You can use Time data type to store type


这篇关于我在MS SQL中为hh:mm tt保存了什么数据类型sholuld的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 22:58