By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,304 Members | 3,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,304 IT Pros & Developers. It's quick & easy.

How to generate number of day in txtDay by subtraction two datetime?

P: 15
public partial class Staff_nHolidayLeave : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnUpdate_Click(object sender, EventArgs e)
{

SqlConnection MyConnection;
SqlCommand MyCommand;

MyConnection = new SqlConnection();
MyConnection.ConnectionString =
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
MyConnection.Open();

MyCommand = new SqlCommand("StoredProcedure4", MyConnection);
MyCommand.CommandType = CommandType.StoredProcedure;
MyCommand.Parameters.Add("@h_name", txtName.Text);
MyCommand.Parameters.Add("@h_from", txtFrom.Text);
MyCommand.Parameters.Add("@h_till", txtTill.Text);
MyCommand.Parameters.Add("@h_day", txtDay.Text);
MyCommand.Parameters.Add("@h_add", txtA1.Text + txtA2.Text);
MyCommand.Parameters.Add("@h_post", txtPost.Text);
MyCommand.Parameters.Add("@h_dept", txtDept.Text);
MyCommand.Parameters.Add("@h_no", txtStaff.Text);
MyCommand.Parameters.Add("@h_hpno", "+6" + txtH.Text + txtP.Text);
MyCommand.Parameters.Add("@h_email", txtEmail.Text);
MyCommand.Parameters.Add("@h_date_apply", DateTime.Today.ToString());

MyCommand.ExecuteScalar();

MyConnection.Close();
Response.Redirect("dLeaveApply.aspx?staff_id=" + Request.QueryString["staff_id"]);
}
protected void btnReset_Click(object sender, EventArgs e)
{
txtName.Text = "";
txtFrom.Text = "";
txtTill.Text = "";
txtDay.Text = "";
txtA1.Text = "";
txtA2.Text = "";
txtPost.Text = "";
txtDept.Text = "";
txtStaff.Text = "";
txtH.Text = "";
txtP.Text = "";
txtEmail.Text = "";


}

public static string Right(string param, int length)
{
//start at the index based on the lenght of the sting minus
//the specified lenght and assign it a variable
string result = param.Substring(param.Length - length, length);
//return the result of the operation
return result;
}
public static string Mid(string param, int startIndex, int length)
{
//start at the specified index in the string ang get N number of
//characters depending on the lenght and assign it to a variable
string result = param.Substring(startIndex, length);
//return the result of the operation
return result;
}

protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Profile.aspx?staff_id=" + Request.QueryString["staff_id"]);
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("ProfileEdit.aspx?staff_id=" + Request.QueryString["staff_id"]);
}
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("PasswordChange.aspx?staff_id=" + Request.QueryString["staff_id"]);
}

protected void Button4_Click(object sender, EventArgs e)
{
Response.Redirect("LeaveApply.aspx?staff_id=" + Request.QueryString["staff_id"]);
}
protected void Button5_Click(object sender, EventArgs e)
{
Response.Redirect("LeaveToday.aspx?staff_id=" + Request.QueryString["staff_id"]);
}
protected void Button6_Click(object sender, EventArgs e)
{
Response.Redirect("LeaveAuthorized.aspx?staff_id=" + Request.QueryString["staff_id"]);
}
protected void Button7_Click(object sender, EventArgs e)
{
Response.Redirect("LeaveUnauthorized.aspx?staff_id =" + Request.QueryString["staff_id"]);
}
protected void Button8_Click(object sender, EventArgs e)
{
Response.Redirect("LeaveCancel.aspx?staff_id=" + Request.QueryString["staff_id"]);
}
protected void Button9_Click(object sender, EventArgs e)
{
Response.Redirect("LeaveNew.aspx?staff_id=" + Request.QueryString["staff_id"]);
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("../Login.aspx");
}


protected void txtDay_Text(object sender, EventArgs e)
{

SqlConnection MyConnection;
SqlCommand cmd;
SqlDataAdapter adt;
DataSet dts;

cmd = new SqlCommand("select * from holiday where h_id='" + Request.QueryString["h_id"] + "'", MyConnection);
adt = new SqlDataAdapter(cmd);
dts = new DataSet();
adt.Fill(dts);

int day = 0;
const int duration = 0;

if (dts.Tables[0].Rows.Count != 0)
{
foreach (DataRow t in dts.Tables[0].Rows)
{
int day = Convert.ToInt32(t[3].ToString()) - Convert.ToInt32(t[2].ToString());
day = day + duration;

}
}


}
}
Mar 14 '08 #1
Share this Question
Share on Google+
2 Replies


P: 28
DateTime now = DateTime.Now;
DateTime past = new DateTime(1997, 1, 1);

TimeSpan span = now - past;
int days = span.Days;
Mar 14 '08 #2

P: 15
DateTime now = DateTime.Now;
DateTime past = new DateTime(1997, 1, 1);

TimeSpan span = now - past;
int days = span.Days;
how to generate no of days in txtDay by substracting datetime that entered in textbox (txtTill) and datetime that entered in textbox(txtFrom)?
Mar 14 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.