检查此源代码中的错误 [英] Check the error from this source code

查看:117
本文介绍了检查此源代码中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%#System.DateTime.Now.Subtract(Eval("Date"))%>

这不是正确的格式,但我想知道如何声明它.
我想从aspx源代码中的当前日期中减去日期.
请帮助我...预先感谢

<%#System.DateTime.Now.Subtract(Eval("Date"))%>

This is not a correct format but i want to know how to declare it.
I want subtract date from current date in aspx source code.
Please help me...Thanks in advance

推荐答案

DateTime.Now.Subtract方法需要DateTime值.如果仅将评估后的语句转换为DateTime,则代码将起作用.

将您的代码更改为以下代码:
DateTime.Now.Subtract method expects a DateTime value. You code shall work if you just convert the evaluated statement to DateTime.

Change your code to the one below:
<%#System.DateTime.Now.Subtract(Convert.ToDateTime(Eval("Date")))%> 


它应该可以工作.

希望这对您有帮助!


and it should work.

Hope this helps!


在这里,如果要从表中获取数据,然后在数据控件中进行绑定,则可以简单地将查询写为


从表名中选择datediff(d,getdate(),date)作为日期

如果您几天之内就想去

其他选择
在aspx.cs页面


DateTime t1 = DateTime.Now;
DateTime t2 =秒日期;
int i = DateTime.Compare(t1,t2);
Here if you are fetching data from a table and then binding in Data Control then you can simply write query as


select datediff(d,getdate(),date)as date from tablename

if you wanr it in days

other option
in aspx.cs page
is

DateTime t1 = DateTime.Now;
DateTime t2 = seconddate;
int i = DateTime.Compare(t1, t2);


这篇关于检查此源代码中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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