473,396 Members | 1,997 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,396 software developers and data experts.

date time difference

Hi,

I have a table which has a field ItemsReceived of type datetime. I
have a grid view which has two columns.

In first column i have to show the data from field ItemsReceived and
in second column I have to show
difference between Currenttime and date from ItemReceived. How can I
do that.

e'g

ItemRecieved Difference
6/13/2007 12:38am 1d 21h 45m
6/13/2007 3:54pm 1d 06h 10m
6/15/2007 12:26pm 34m

So the second coulmn displays the difference of current time minus
ItemRecieved. the format shouild be <mintues>m,
or<hours>h, <mintues>m, or <days>d.

How can I do that.

Thanks in advance

Jun 15 '07 #1
3 4131
Hi there,

I prepared an example that you get you on the right track:

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
gridView.DataSource = GetData();
gridView.DataBind();
}

private System.Data.DataTable GetData()
{
System.Data.DataTable table =
new System.Data.DataTable();

table.Columns.Add("Id", typeof(int));
table.Columns.Add("ItemRecieved", typeof(DateTime));
table.Columns.Add("Difference", typeof(TimeSpan));
//t.ColumnChanged += new DataColumnChangeEventHandler(t_ColumnChanged);
table.ColumnChanged +=
new System.Data.DataColumnChangeEventHandler(table_Col umnChanged);

for (int i = 0; i < 10; i++)
{
System.Data.DataRow row = table.NewRow();
row[0] = i;
row[1] = DateTime.Now.AddDays((double)i);
table.Rows.Add(row);
}

return table;
}

private void table_ColumnChanged(object sender,
System.Data.DataColumnChangeEventArgs e)
{
if (e.Column.ColumnName == "ItemRecieved")
{
DateTime date = (DateTime)e.Row["ItemRecieved"];
e.Row["Difference"] = DateTime.Now - date;
}
}
</script>

<asp:GridView runat="server" ID="gridView"
AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" />
<asp:BoundField DataField="ItemRecieved" />
<asp:BoundField DataField="Difference"
DataFormatString="{0:-d.hh:mm:ss}" />
</Columns>
</asp:GridView>

Hope this helps

--
Milosz
"bb****@yahoo.com" wrote:
Hi,

I have a table which has a field ItemsReceived of type datetime. I
have a grid view which has two columns.

In first column i have to show the data from field ItemsReceived and
in second column I have to show
difference between Currenttime and date from ItemReceived. How can I
do that.

e'g

ItemRecieved Difference
6/13/2007 12:38am 1d 21h 45m
6/13/2007 3:54pm 1d 06h 10m
6/15/2007 12:26pm 34m

So the second coulmn displays the difference of current time minus
ItemRecieved. the format shouild be <mintues>m,
or<hours>h, <mintues>m, or <days>d.

How can I do that.

Thanks in advance

Jun 15 '07 #2
On Jun 15, 4:16 pm, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
wrote:
Hi there,

I prepared an example that you get you on the right track:

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
gridView.DataSource = GetData();
gridView.DataBind();

}

private System.Data.DataTable GetData()
{
System.Data.DataTable table =
new System.Data.DataTable();

table.Columns.Add("Id", typeof(int));
table.Columns.Add("ItemRecieved", typeof(DateTime));
table.Columns.Add("Difference", typeof(TimeSpan));
//t.ColumnChanged += new DataColumnChangeEventHandler(t_ColumnChanged);
table.ColumnChanged +=
new System.Data.DataColumnChangeEventHandler(table_Col umnChanged);

for (int i = 0; i < 10; i++)
{
System.Data.DataRow row = table.NewRow();
row[0] = i;
row[1] = DateTime.Now.AddDays((double)i);
table.Rows.Add(row);
}

return table;

}

private void table_ColumnChanged(object sender,
System.Data.DataColumnChangeEventArgs e)
{
if (e.Column.ColumnName == "ItemRecieved")
{
DateTime date = (DateTime)e.Row["ItemRecieved"];
e.Row["Difference"] = DateTime.Now - date;
}}

</script>

<asp:GridView runat="server" ID="gridView"
AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" />
<asp:BoundField DataField="ItemRecieved" />
<asp:BoundField DataField="Difference"
DataFormatString="{0:-d.hh:mm:ss}" />
</Columns>
</asp:GridView>

Hope this helps

--
Milosz

"bba...@yahoo.com" wrote:
Hi,
I have a table which has a field ItemsReceived of type datetime. I
have a grid view which has two columns.
In first column i have to show the data from field ItemsReceived and
in second column I have to show
difference between Currenttime and date from ItemReceived. How can I
do that.
e'g
ItemRecieved Difference
6/13/2007 12:38am 1d 21h 45m
6/13/2007 3:54pm 1d 06h 10m
6/15/2007 12:26pm 34m
So the second coulmn displays the difference of current time minus
ItemRecieved. the format shouild be <mintues>m,
or<hours>h, <mintues>m, or <days>d.
How can I do that.
Thanks in advance- Hide quoted text -

- Show quoted text -
Here I am grabbing Itemrecieved and ID from the tables. I am using
the following query. In your code where should I use that query to get
other fields.

select tck.tcktreceived, tck.ticketid, tckmsg.tcktmessage
from tbtickets tck inner join tbticketsmessages tckmsg
on tck.ticketid = tckmsg.ticketid.

Jun 16 '07 #3
Howdy,

Pseudocode:

DataTable table = new DataTable();

table.Columns.Add("Difference", typeof(TimeSpan));
table.ColumnChanged +=
new System.Data.DataColumnChangeEventHandler(table_Col umnChanged);

using (SqlConnection connection = new SqlConnection(ConnectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter(query, connection);
adapter.Fill(table);
}

You should be fine from this point.
--
Milosz
"bb****@yahoo.com" wrote:
On Jun 15, 4:16 pm, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
wrote:
Hi there,

I prepared an example that you get you on the right track:

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
gridView.DataSource = GetData();
gridView.DataBind();

}

private System.Data.DataTable GetData()
{
System.Data.DataTable table =
new System.Data.DataTable();

table.Columns.Add("Id", typeof(int));
table.Columns.Add("ItemRecieved", typeof(DateTime));
table.Columns.Add("Difference", typeof(TimeSpan));
//t.ColumnChanged += new DataColumnChangeEventHandler(t_ColumnChanged);
table.ColumnChanged +=
new System.Data.DataColumnChangeEventHandler(table_Col umnChanged);

for (int i = 0; i < 10; i++)
{
System.Data.DataRow row = table.NewRow();
row[0] = i;
row[1] = DateTime.Now.AddDays((double)i);
table.Rows.Add(row);
}

return table;

}

private void table_ColumnChanged(object sender,
System.Data.DataColumnChangeEventArgs e)
{
if (e.Column.ColumnName == "ItemRecieved")
{
DateTime date = (DateTime)e.Row["ItemRecieved"];
e.Row["Difference"] = DateTime.Now - date;
}}

</script>

<asp:GridView runat="server" ID="gridView"
AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" />
<asp:BoundField DataField="ItemRecieved" />
<asp:BoundField DataField="Difference"
DataFormatString="{0:-d.hh:mm:ss}" />
</Columns>
</asp:GridView>

Hope this helps

--
Milosz

"bba...@yahoo.com" wrote:
Hi,
I have a table which has a field ItemsReceived of type datetime. I
have a grid view which has two columns.
In first column i have to show the data from field ItemsReceived and
in second column I have to show
difference between Currenttime and date from ItemReceived. How can I
do that.
e'g
ItemRecieved Difference
6/13/2007 12:38am 1d 21h 45m
6/13/2007 3:54pm 1d 06h 10m
6/15/2007 12:26pm 34m
So the second coulmn displays the difference of current time minus
ItemRecieved. the format shouild be <mintues>m,
or<hours>h, <mintues>m, or <days>d.
How can I do that.
Thanks in advance- Hide quoted text -
- Show quoted text -

Here I am grabbing Itemrecieved and ID from the tables. I am using
the following query. In your code where should I use that query to get
other fields.

select tck.tcktreceived, tck.ticketid, tckmsg.tcktmessage
from tbtickets tck inner join tbticketsmessages tckmsg
on tck.ticketid = tckmsg.ticketid.

Jun 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: akoper | last post by:
I have a table that is a project. Each record is a task in the project. One field in each record is a date/time stamp for when that task was completed. I need to be able to: 1) compute how much...
28
by: Steve | last post by:
Hi all How would I find out the average date when given a bunch of dates? For example, I want to find the average length in time from the following dates:...
4
by: qtip | last post by:
I have a simple table the has First Name , Last Name, SSN, Date&Time. I have a report that will show all this information but I would like to put in at calculation to tell the difference between 2...
3
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
7
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from...
5
by: Geoff Jones | last post by:
Hi I have question regarding times and dates in a datatable. I have one table with one column having the date e.g.03/09/04, and another column other the time 08:03:05. The other table has one...
6
by: Scott | last post by:
I have a start date and an end date in my project that is defaulted to the current date at run-time using the following code... Date1.Value = Now() Date2.Value = Now() I then have some code...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.