| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 426 人关注过本帖
标题:关于根据日期字段从数据库查数据的问题
只看楼主 加入收藏
summoner
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1622
专家分:0
注 册:2005-3-3
收藏
 问题点数:0 回复次数:1 
关于根据日期字段从数据库查数据的问题
数据库中日期字段为datetime类型,如何根据Calendar控件中选定的日期从数据库中查出符合该日期的值,如果是用like,那like 后面应该怎么写?
搜索更多相关主题的帖子: 数据库 字段 
2006-05-25 21:35
铲铲
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:34
帖 子:506
专家分:0
注 册:2006-5-2
收藏
得分:0 

使用DATEDIFF函数,用法如下:

The DATEDIFF function calculates the period of time in dateparts between the second and first of two dates you specify. In other words, it finds an interval between two dates. The result is a signed integer value equal to date2 - date1 in date parts.

The following query uses the date November 30, 2001, and finds the number of days that elapsed between DueDate and that date:

USE AdventureWorks;
GO
SELECT DATEDIFF(day, DueDate, 'Nov 30 2001')
FROM Sales.SalesOrderHeader;
GO

For the rows in SalesOrderHeader that have having a DueDate of October 21, 1995, the result produced by the last query is 40. (There are 40 days between October 21 and November 30.) To calculate an interval in months, use the following query:

USE AdventureWorks;
GO
SELECT interval = DATEDIFF(month, DueDate, 'Nov 30 2001')
FROM Sales.SalesOrderHeader;
GO

The query produces a value of 1 for the rows with a DueDate in October and a value of 5 for the rows with a DueDate in June.

When the first date in the DATEDIFF function is later than the second date specified, the resulting value is negative.

If one or both of the date arguments is a smalldatetime value, they are converted to datetime values internally for the calculation. Seconds and milliseconds in smalldatetime values are automatically set to 0 for calculation.

这是从MSDN上摘抄,其实你可以自己到微软官方的MSDN上找找相关资料


铲铲是也
2006-05-26 08:56
快速回复:关于根据日期字段从数据库查数据的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040673 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved