计算我的天数增加到2个问题..

编程入门 行业动态 更新时间:2024-10-25 08:16:35
本文介绍了计算我的天数增加到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

推荐答案

为什么要这么乱?请参阅: msdn.microsoft/en -us / library / system.datetime.aspx [ ^ ], http ://msdn.microsoft/en-us/library/system.datetime.adddays.aspx [ ^ ], msdn.microsoft/en-us/library/system.datetime.addmonths.aspx [ ^ ]。 您是否考虑到不同的年份和月份有不同的天数等?随你。如果您只是想自学编程,请使用调试器并检查您的中间数字应该是预期的。
-SA
Why doing all that mess? Please see: msdn.microsoft/en-us/library/system.datetime.aspx[^], msdn.microsoft/en-us/library/system.datetime.adddays.aspx[^], msdn.microsoft/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个问题..

本文发布于:2023-10-28 08:26:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536087.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:天数   增加到

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!