473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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
2 2067
int08h
28
DateTime now = DateTime.Now;
DateTime past = new DateTime(1997, 1, 1);

TimeSpan span = now - past;
int days = span.Days;
Mar 14 '08 #2
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

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

Similar topics

3
by: Mohit Gupta | last post by:
How do I generate Big Integers in VB .NET? For example, if I have a number like 98908324328432864872364234623874682342234234242342 that can't be stored in INT64 or INT32 type variable. How...
10
by: Scott Kilbourn | last post by:
Hi, Does anyone know how to accurately calculate the number of days that have elapsed since 01/01/0000? I'd appreciate any help anyone could give me. Thanks
3
by: Mohit Gupta | last post by:
How do I generate Big Integers in VB .NET? For example, if I have a number like 98908324328432864872364234623874682342234234242342 that can't be stored in INT64 or INT32 type variable. How...
14
by: Anthony Liu | last post by:
I am at my wit's end. I want to generate a certain number of random numbers. This is easy, I can repeatedly do uniform(0, 1) for example. But, I want the random numbers just generated sum up...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.