计算我的天数增加到2个问题.. [英] Calculating my days increment to 2 problem..

查看:156
本文介绍了计算我的天数增加到2个问题..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


我的日子有问题..因为我进入1年3个月和1天......它应该是456 ..而不是1天它给了我3天比如增加2,等于458天。它对于几个月和几天来说是相同的。它和它提供了正确的输出但是包括所有(年,月,日)它也给出了错误的结果..我更喜欢结果几天不能完美地工作



hi
my days till has the problem..since i enter 1 year 3months and 1 day...it should be 456..instead of 1day it gives me 3 days like it increment by 2,equal to 458days. it is the same for Months and days.Years and Days it gives correct output but to include all(year,months, days,) it gives the wrong result as well..i prefer the result for days not work perfectly

Public Function RaceDate(length  As Integer ) As String

              dim year As string=0
              dim month As string=0
              dim day As string=0
              dim ReturnString As string

ReturnString=""

If length = 0 then
Return String.Empty
end if

if length >= 365
year=cstr((Math.Floor (length / 365)))
length  =(length  Mod 365)

end if

If length >= 30 AndAlso length < 365 Then
month =cstr((Math.Floor(length / 30 )))
length  =(length  Mod 30)


end if

if length < 30 Then
day =cstr(length)
End If

If cint(year) >0
ReturnString= year+"  Years  "

End if

If cint(month) >0

ReturnString= ReturnString +month+" Months "

End if

If cint(day) >0

ReturnString = ReturnString+day+ " Days "

End if

Return (ReturnString)

End Function





提前感谢



thanks in advance

推荐答案

为什么要这么乱?请参阅:

http://msdn.microsoft.com/en -us / library / system.datetime.aspx [ ^ ],

http ://msdn.microsoft.com/en-us/library/system.datetime.adddays.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.datetime.addmonths.aspx [ ^ ]。



您是否考虑到不同的年份和月份有不同的天数等?随你。如果您只是想自学编程,请使用调试器并检查您的中间数字应该是预期的。



-SA
Why doing all that mess? Please see:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^],
http://msdn.microsoft.com/en-us/library/system.datetime.adddays.aspx[^],
http://msdn.microsoft.com/en-us/library/system.datetime.addmonths.aspx[^].

Do you take into account that different years and months have different number of days, etc? Whatever. If you just want to teach yourself to program, use the debugger and check up your intermediate number with what should be expected.

—SA


使用它,一定会有效。



Use this, will definitely work.

SELECT DATEADD(day,2,OrderDate) AS OrderPayDate
FROM Orders





如果有帮助,请标记为答案。



Please mark as answer if helped.


使用 DateTime.AddDays DateTime.AddMonths 方法..


这篇关于计算我的天数增加到2个问题..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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