473,769 Members | 6,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4161
Hi there,

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

<script runat="server">

protected void Page_Load(objec t sender, EventArgs e)
{
gridView.DataSo urce = GetData();
gridView.DataBi nd();
}

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

table.Columns.A dd("Id", typeof(int));
table.Columns.A dd("ItemRecieve d", typeof(DateTime ));
table.Columns.A dd("Difference" , typeof(TimeSpan ));
//t.ColumnChanged += new DataColumnChang eEventHandler(t _ColumnChanged) ;
table.ColumnCha nged +=
new System.Data.Dat aColumnChangeEv entHandler(tabl e_ColumnChanged );

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

return table;
}

private void table_ColumnCha nged(object sender,
System.Data.Dat aColumnChangeEv entArgs e)
{
if (e.Column.Colum nName == "ItemReciev ed")
{
DateTime date = (DateTime)e.Row["ItemReciev ed"];
e.Row["Difference "] = DateTime.Now - date;
}
}
</script>

<asp:GridView runat="server" ID="gridView"
AutoGenerateCol umns="false">
<Columns>
<asp:BoundFie ld DataField="Id" />
<asp:BoundFie ld DataField="Item Recieved" />
<asp:BoundFie ld DataField="Diff erence"
DataFormatStrin g="{0:-d.hh:mm:ss}" />
</Columns>
</asp:GridView>

Hope this helps

--
Milosz
"bb****@yahoo.c om" 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...@DONTLI KESPAMwp.pl>
wrote:
Hi there,

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

<script runat="server">

protected void Page_Load(objec t sender, EventArgs e)
{
gridView.DataSo urce = GetData();
gridView.DataBi nd();

}

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

table.Columns.A dd("Id", typeof(int));
table.Columns.A dd("ItemRecieve d", typeof(DateTime ));
table.Columns.A dd("Difference" , typeof(TimeSpan ));
//t.ColumnChanged += new DataColumnChang eEventHandler(t _ColumnChanged) ;
table.ColumnCha nged +=
new System.Data.Dat aColumnChangeEv entHandler(tabl e_ColumnChanged );

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

return table;

}

private void table_ColumnCha nged(object sender,
System.Data.Dat aColumnChangeEv entArgs e)
{
if (e.Column.Colum nName == "ItemReciev ed")
{
DateTime date = (DateTime)e.Row["ItemReciev ed"];
e.Row["Difference "] = DateTime.Now - date;
}}

</script>

<asp:GridView runat="server" ID="gridView"
AutoGenerateCol umns="false">
<Columns>
<asp:BoundFie ld DataField="Id" />
<asp:BoundFie ld DataField="Item Recieved" />
<asp:BoundFie ld DataField="Diff erence"
DataFormatStrin g="{0:-d.hh:mm:ss}" />
</Columns>
</asp:GridView>

Hope this helps

--
Milosz

"bba...@yahoo.c om" 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.tcktreceive d, tck.ticketid, tckmsg.tcktmess age
from tbtickets tck inner join tbticketsmessag es tckmsg
on tck.ticketid = tckmsg.ticketid .

Jun 16 '07 #3
Howdy,

Pseudocode:

DataTable table = new DataTable();

table.Columns.A dd("Difference" , typeof(TimeSpan ));
table.ColumnCha nged +=
new System.Data.Dat aColumnChangeEv entHandler(tabl e_ColumnChanged );

using (SqlConnection connection = new SqlConnection(C onnectionString ))
{
SqlDataAdapter adapter = new SqlDataAdapter( query, connection);
adapter.Fill(ta ble);
}

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

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

<script runat="server">

protected void Page_Load(objec t sender, EventArgs e)
{
gridView.DataSo urce = GetData();
gridView.DataBi nd();

}

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

table.Columns.A dd("Id", typeof(int));
table.Columns.A dd("ItemRecieve d", typeof(DateTime ));
table.Columns.A dd("Difference" , typeof(TimeSpan ));
//t.ColumnChanged += new DataColumnChang eEventHandler(t _ColumnChanged) ;
table.ColumnCha nged +=
new System.Data.Dat aColumnChangeEv entHandler(tabl e_ColumnChanged );

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

return table;

}

private void table_ColumnCha nged(object sender,
System.Data.Dat aColumnChangeEv entArgs e)
{
if (e.Column.Colum nName == "ItemReciev ed")
{
DateTime date = (DateTime)e.Row["ItemReciev ed"];
e.Row["Difference "] = DateTime.Now - date;
}}

</script>

<asp:GridView runat="server" ID="gridView"
AutoGenerateCol umns="false">
<Columns>
<asp:BoundFie ld DataField="Id" />
<asp:BoundFie ld DataField="Item Recieved" />
<asp:BoundFie ld DataField="Diff erence"
DataFormatStrin g="{0:-d.hh:mm:ss}" />
</Columns>
</asp:GridView>

Hope this helps

--
Milosz

"bba...@yahoo.c om" 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.tcktreceive d, tck.ticketid, tckmsg.tcktmess age
from tbtickets tck inner join tbticketsmessag es 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
8592
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 time has passed between each date/time stamp and 2) compute how much time has passed between the first and last date/time stamp (total project time). This involves a self join, and I have nearly gotten it to work, but I need a little more help. ...
28
742
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: ---------------------------------------------------- Start Date End Date 01/01/2004 12:50pm 02/01/2004 18:40pm 02/01/2004 13:40pm 02/01/2004 13:57pm 02/01/2004 14:30pm 02/01/2004 19:50pm
4
2645
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 Date&time stamps for the person. The report shows Last name, First Name and Date&Tiem Field. If the persone has 2 records I would like to show the amount of time between each in put.
3
35100
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
8499
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 the Toolbox and then set the Format property appropriately. I have noticed that sometimes the Time format will reset spontaneously to Short Date. I looked at the .rc file and found that the usual form for a Short Date is as follows: CONTROL ...
5
1469
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 column with the date/time e.g. 09/06/04 13:05:03. What is the easiest way for me to calculate the difference in time, in seconds, between the rows of each table?
6
1677
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 that works out the number of days between the 2 dates as follows... Dim d1, d2 As Date
4
15758
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 which calculated the difference in years and days between two dates, and takes leap years into account? I'm calculating the difference in the usual way, i.e....
44
10234
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
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.