如何在注册表中计算时间. [英] How to count the time in a registration form.
本文介绍了如何在注册表中计算时间.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在注册表中计算完成注册的时间.
我想在用户完成一年后给我一个消息.
我的registration.cs编码如下所示:
How to count the time for complition of registration in a registration form.
I want to give a message when one year complete of a user.
My coading of registration.cs is given below
if (Page.IsValid==true)
{
string sc1 = "";
if (rbStudent.Checked == true)
{
sc1 = "Student";
}
if (rbPFaculty.Checked == true)
{
sc1 = "Private Faculty";
}
if (rbSFaculty.Checked == true)
{
sc1 = "School Faculty";
}
SqlConnection CON = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["tuitionConnectionString"].ConnectionString);
SqlTransaction tr = null;
CON.Open();
tr = CON.BeginTransaction();
try
{
SqlCommand cmd = new SqlCommand("insert into registration (email,fname,lname,pass,dob,cont,rtype,tclass,school,board,city,pcode,state) values (@email,@fname,@lname,@pass,@dob,@cont,@rtype,@tclass,@school,@board,@city,@pcode,@state)");
//,@cont,@rtype,@tclass,@board,@city,@pcode,@state)");
cmd.Transaction = tr;
cmd.Parameters.AddWithValue("@email", txtEmail.Text);
cmd.Parameters.AddWithValue("@fname", txtFname.Text);
cmd.Parameters.AddWithValue("@lname", txtLname.Text);
cmd.Parameters.AddWithValue("@pass", txtPass.Text);
cmd.Parameters.AddWithValue("@dob", txtDob.Text);
cmd.Parameters.AddWithValue("@cont", txtCno.Text);
cmd.Parameters.AddWithValue("rtype", sc1.ToString());
cmd.Parameters.AddWithValue("@tclass", ddClass.SelectedItem.Text);
cmd.Parameters.AddWithValue("@school", txtSchool.Text);
cmd.Parameters.AddWithValue("@board", ddBoard.SelectedItem.Text);
cmd.Parameters.AddWithValue("@city", ddCity.SelectedItem.Text);
cmd.Parameters.AddWithValue("@pcode", txtPCode.Text);
cmd.Parameters.AddWithValue("@state", ddState.SelectedItem.Text);
cmd.Connection = CON;
cmd.ExecuteNonQuery();
tr.Commit();
}
catch (Exception ex)
{
Response.Write("" + ex);
tr.Rollback();
}
finally
{
CON.Close();
}
}
推荐答案
从数据库中获取注册信息时,yuo可以使用例如DATEDIFF [ ^ ]检查注册到当前日期(GETDATE()
)之间的经过时间
When you fetch the registration information from the database, yuo can use for example DATEDIFF[^] to check the amount of elapsed time between the registration and current date (GETDATE()
)
Janardan
要计算时间,您需要使用DateDiff
首先要计算小时,分钟或秒数
我sql,您必须在下面执行此操作
假设您在数据库startTime和EndTime中使用了两个字段
您的查询将是
对于小时数计算:
Hi Janardan
To calculate Time yes you need to use DateDiff
first what you want to calculate Hour,minutes or second
I sql you have to do this below
Suppose two field you used in database startTime and EndTime
your query will be
For Hours calculation:
(Select DateDiff(Hour,StartTime,EndTime)as TotalHours)as Hours
用于分钟计算:
For Minute calculation:
(Select DateDiff(Minute,StartTime,EndTime)as TotalHours)as Minute
对于第二次计算:
For Second calculation:
(Select DateDiff(Second,StartTime,EndTime)as TotalHours)as Second
这篇关于如何在注册表中计算时间.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文