从我的数据库中获取日期. [英] getting date from my database..

查看:96
本文介绍了从我的数据库中获取日期.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi ..

我有一个表,其中包含列来源,目的地,日期和时间,客户ID..
但是我只提供源,目的地和日期作为输入.在我希望将时间作为输出的地方.是否有可能在特定日期获得时间?

hi..

i''m having a table with columns source,destination,date and time,customer id..
but i''l give source,destination and date alone as input..where as i want the time as output..is it possible to get time on particular date??

推荐答案

可以获取时间和日期,但是它将是默认值.示例:
It is possible to get time along with date, but it will be the default value. Example:
Create table test_table (Idfield int, dateOne datetime, dateTwo smalldatetime);
-- input only date field..
insert into test_table values (1, '10/10/2011','10/11/2011');
select * from test_table 
--Output will be 
1	2011-10-10 00:00:00.000	2011-10-11 00:00:00


没有Time数据类型,它存储为DateTime的一部分,该日期以毫秒为单位,从过去任意点开始保存.
根据您要执行此操作的位置,可以使用带有参数"hh:mm"或"HH:mm"的DateTime.ToString方法来检索DateTime并将其格式化以显示在ASP代码中.此处的格式说明符:格式化显示的DateTime-格式字符串说明 [ ^ ])
或者如果要在SQL中执行此操作,则可以将其返回为int或string:

There is no Time datatype, it is stored as part of the DateTime, which is held in terms of milliseconds since an arbitrary point in teh past.
Depending on where you want to do this, you can retrieve the DateTime and format it for display in your ASP code, using the DateTime.ToString Method with the parameter "hh:mm" or "HH:mm" (there is a list of the format specifiers here: Formatting a DateTime for display - format string description[^])
or if you want to do it in SQL , you can return it as int, or string:

DECLARE @DT as Datetime
SET @DT='2011-01-13 12:28'
SELECT DATEPART(hour, @DT), DATEPART(minute, @DT), CAST(DATEPART(hour, @DT) AS VARCHAR(2)) + ':' + CAST(DATEPART(minute, @DT) AS VARCHAR(2))


这篇关于从我的数据库中获取日期.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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