将整数转换为日期时间并进行比较 [英] Converting integer to datetime and compare

查看:102
本文介绍了将整数转换为日期时间并进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有两个表tbl1和tbl2.

在tbl1中,我有两列Month和Year,它们都是数字字段.

在tbl2中,我有一个名为monthyear的列,其数据类型为datetime并包含
日期.

我想要的是比较此tbl2 monthyear列的月份和年份部分
与tbl1的month and year列的组合.

例如tbl1 =月份年份
2010年1月1日
7 2010

tbl2 = monthyear
2010-01-31
2010-07-31

我只想从tbl2中获取其中monthyear列包含相同内容的行
tbl1中的月份和年份.
我该如何进行比较?
有帮助吗?

Hi guys

I have two tables tbl1 and tbl2 .

In tbl1 i have two columns Month and Year there both are numeric fileds.

and in tbl2 i have a columns named monthyear its data type is datetime and contains
dates .

What i want is to compare month and year part of this tbl2 monthyear column
with the combination of month and year column of the tbl1 .

e.g tbl1= Month Year
1 2010
7 2010

tbl2= monthyear
2010-01-31
2010-07-31

I want to get only those rows from tbl2 where monthyear column contains same
Month and Year in the tbl1 .
how can i make this comparison ?
any help ?
regards.

推荐答案

您的问题的标题与.net有关,但在问题中您提到了表格.因此尚不完全清楚.

C#:DateTime.YearDateTime.Month可用于比较月份和年份的值
T-SQL:可以使用YEARMONTH.

祝你好运!
The title of your question is about .net but in the question you mention tables. So it isn''t completely clear.

C# : DateTime.Year and DateTime.Month can be used to compare month and year value
T-SQL: YEAR and MONTH can be used.

Good luck!


尝试此查询...........


try this query...................


select t1.* from
tbl1 t1, tbl2 tbl2
where t1.month = convert(int, datepart(mm, t2.datecolumn)
and t1.year = convert(int, datepart(yyyy, t2.datecolumn)


这篇关于将整数转换为日期时间并进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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