从提交日期开始计算ASP.NET中的老化 [英] Calculate ageing in ASP.NET from the date of submission

查看:75
本文介绍了从提交日期开始计算ASP.NET中的老化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我正在开发一个项目,为此我需要计算'老龄化'。老龄化将显示在另一页中,并且应该每天都在增加。

老化将计算为(提交表格的日期 - 今天的日期)。当表格是提交的Aging也会保存在SQL数据库中。

到目前为止我所做的是提交按钮点击事件我已将表单提交的日期存储在变量'Now'中。并计算老龄化,我从它减去今天的日期。

以下是我的代码

  string  Aging =(DateTime.Today。减去(Convert.ToDateTime(now))。TotalDays).ToString(); 





但问题是它不随每个增加天。就像用户今天提交一个案例即(2016年10月5日)并且最初老化应该是0,因为提交日期表格并且当前日期是相同的,因此在减去它们之后它应该是0.但是当用户来时明天即(2016年10月6日),检查老化应该是1,并且应该自动逐日增加。

请帮助,我们将非常感谢您的帮助。



我尝试了什么:



我尝试过使用上面提到的代码但是每当用户提交表单。它将老化存储为0并且永远不会增加。

我希望它每天都会增加。

如果案例是在2月10日提交的话2016年和今天是2016年10月5日所以它应该显示老龄化为3.(自2016年10月5日起 - (2016年10月2日)= 3)

解决方案

这可能有所帮助:使用年龄:它与TimeSpan不同! [ ^ ]


好吧,此时我们只知道 Aging 字段没有增加,但我们不知道您的解决方案有什么问题。我们对用于增加该字段的方法一无所知!



因此,我建议首先阅读解决方案1中提供的文章 OriginalGriff [ ^ ]。



如果您想计算天数差异在两个日期之间,你可以使用类似的东西:

 DateTime startDate =  new  DateTime( 2016  10  2 ); 
DateTime endDate = new DateTime( 2016 10 5 );

var daydiff =(endDate-startDate).TotalDays;
// 返回:3





但是......如果你想在SQL Server上计算它,你必须使用 DateDiff功能 [ ^ ]:



  SELECT  DATEDIFF(DD,< span class =code-string>'  2016-10-02''  2016-10-05' AS 老化
- 返回:3





祝你好运!


从字符串轻松解析为Datetime;



 DateTime TotalDays = DateTime.ParseExact(sample .text, < span class =code-string> dd / MM / yyyy,System.Globalization.CultureInfo.InvariantCulture); 
字符串 Aging =(DateTime.Now.Subtract((DateTime)TotalDays).Days).ToString();


Hello,

I am developing a project and for that i need to calculate the 'Ageing'. The Ageing will be displayed in another page and should keep on increasing with each passing day.
The Ageing will be calculated as (The date when the form is submitted - Today's Date).And when the form is submitted the Ageing also gets saved in SQL database.
What i have done so far is on the Submit button click event i have stored the date of form submission in a variable 'Now'. And to calculate the Ageing i have subtracted Today's Date from it.
Below is my code

string Ageing = (DateTime.Today.Subtract(Convert.ToDateTime(now)).TotalDays).ToString();



But the problem is it does not increment with each day. Like if a user submits a case today i-e (5-Oct-2016) and initially the ageing should be 0, because the date form is submitted and current date is the same so after subtracting them it should be 0. But when a User comes tomorrow i-e (6-Oct-2016) and check the ageing it should be 1 and should keep on increasing with each passing day automatically.
Please help, your help would be highly appreciated.

What I have tried:

I have tried using the above mentioned code but whenever user submits the form. It stores the ageing as 0 and it never gets incremented.
I want it to getting increased by each passing day.
Like if the case was submitted on 2-Oct-2016 and today is 5-Oct-2016 so it should show Ageing as 3. (Since (5-Oct-2016) - (2-Oct-2016) = 3)

解决方案

This may help: Working with Age: it's not the same as a TimeSpan![^]


Well, at this moment we know only that Ageing field is not getting increased, but we don't know what's wrong with your solution. And we know nothing about method used to increase that field!

So, i'd suggest to start with reading article provided in solution 1 by OriginalGriff[^].

If you would like to calculate the difference in days between two dates, you can use something like that:

DateTime startDate = new DateTime(2016,10,2);
DateTime endDate = new DateTime (2016,10,5);

var daydiff = (endDate-startDate).TotalDays;
//returns: 3



But... if you would like to calculate it on SQL Server, you have to use DateDiff function[^]:

SELECT DATEDIFF(DD, '2016-10-02', '2016-10-05') AS Ageing
--returns: 3



Good luck!


Easy parse from string into Datetime;

DateTime TotalDays = DateTime.ParseExact(sample.text,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture);
String Ageing = (DateTime.Now.Subtract((DateTime)TotalDays).Days).ToString();


这篇关于从提交日期开始计算ASP.NET中的老化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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