选择的年,月和日. [英] selected years, months and days.

查看:95
本文介绍了选择的年,月和日.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码运行得很好,但是我想使用我的表达式(如果有的话)或者我可以在表达式中使用它来仅选择年,月和日.例如,如果我的输出是3 Year = 3years而不是3years, 0month,0days和7months应该仅显示7个月,而不显示0years,7months,0days和days为6days,而不是0 Year 0months and 6 days.
这是我表达中的代码

=code.GetCustomDate(avg(Fields!SentenceLength.Value))

i have my code which runs fine, but i want to use my expression if any or can i do in my expression to select only of years,months and days.example if my output is 3 years=3years and not 3years,0month,0days, and 7months should only display 7 months and not 0years,7months,0days as well as days to be 6days rather than 0 years 0months and 6 days.
here is my code in my expression

=code.GetCustomDate(avg(Fields!SentenceLength.Value))

Public Function GetCustomDate(ByVal days As Int32) As String
        Dim objDate1 As DateTime = DateTime.Now()
        Dim objDate2 As DateTime = objDate1.AddDays(-1 * days)
'This has to be modified as not correct.
        Return "Years = " & (objDate1.Year - objDate2.Year) & " Months = " & (objDate1.Month - objDate2.Month) & " Days = " & (objDate1.Day - objDate2.Day)
    End Function



在此先感谢



thanks in advance

推荐答案

请查看我对这个问题的评论:您将其表述为错误还是做错了.
在此回答有关该主题的所有可疑问题:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.timespan.aspx [^ ]

并且:

http://msdn.microsoft.com/en-us/library/dd992632.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/ee372286.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/ee372287.aspx [ ^ ].

请注意第二个链接:时间跨度和时间是不同的东西.如果要显示时间跨度,请计算时间跨度;而您在最后一年和一年中进行某些操作的最后一行在概念上可能是错误的.您可以通过减法运算符获取时间跨度:

Please see my comment to the question: you either formulate it wrong or do it wrong.
All thinkable questions on the topic are answered here:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^],
http://msdn.microsoft.com/en-us/library/system.timespan.aspx[^]

and also:

http://msdn.microsoft.com/en-us/library/dd992632.aspx[^],
http://msdn.microsoft.com/en-us/library/ee372286.aspx[^],
http://msdn.microsoft.com/en-us/library/ee372287.aspx[^].

Pay attention for the second link: time span and time are different things. If you want to present time span, calculate time span; and your last line doing some operations on the year and month may be conceptually wrong. You can get time span by subtraction operator:

Dim timeSpan as System.TimeSpan
timeSpan = objDate2 - objDate1; ' as simple as that



然后从那里去.

-SA



And go from there.

—SA


您可能需要查看年,月,日,并检查它们是否为0,然后才能构建显示字符串.

例如

you may need to look at the years, months, days and check to see if they are 0 before building a display string.

e.g.

if iYear > 0 then
 sDisp = sDisp & iYear.tostring & "Years "
End if


这篇关于选择的年,月和日.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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