This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - How to get the Time Difference

krish80 - Thursday, April 23, 2009 6:36 AM:

Hi,

How to get the time difference.

Example : In a Form having Two Fields (Date Field's) Like 1. Start date 2. End date . While i process the form  i click & select the start date and i didnt do any thing with End Date Field (Just Blank). Now i submit (save) the form.

After some times i reopen (Modify)  the same form and i click & select the End Date field , Now i submit the form. 

So the fields having the values of like below :

Start_Date : 04/23/2009 10:23:35 AM

End_Date : 04/23/2009   03:20:22 PM

How to get the duration between this Hours &  wants to update this into another ItemType field. (duration_time)

Guid me how to do this in server side.......

Thanks & Regards,

Krish

 



SamsAn - Thursday, April 23, 2009 12:25 PM:

Use onBeforeAdd and(or) onBeforeUpdate server side event method.
C# methods portions should be like:
string neutralFormat = "yyyy-MM-ddTHH:mm:ss";
DateTime startDt = DateTime.ParseExact(this.getProperty("start_date"), neutralFormat);
DateTime endDt = DateTime.ParseExact(this.getProperty("end_date"), neutralFormat);
//..... Code to find differenece
this.setProperty("end_date", calculatedDiff);



Sean - Friday, April 24, 2009 2:24 PM:

Krish,

Here is some sample code that will get the date diff for you:

The method should be attached to an onBeforeUpdate and if necessary an onBeforeAdd event.  The method is as follows:
 

 

Innovator inn = this.getInnovator();
string
startDtStr = this.getProperty("start_date","");
string
endDtStr = this.getProperty("finish_date","");
if
(startDtStr =="" || endDtStr=="")
{
return this;
}
else

{
DateTime startDt = DateTime.Parse(startDtStr);
DateTime endDt = DateTime.
Parse(endDtStr);
if
(DateTime.Compare(endDt, startDt) <= 0)
{
Item err = inn.newError("Your finish date must be greater than your start date!!!");
return
err;
}
else
{
TimeSpan dateDiff = endDt - startDt;
int
days = dateDiff.Days;
int
hours = dateDiff.Hours;
int
minutes = dateDiff.Minutes;
float
hoursTotal = ((float)days*24) + (float)hours + ((float)minutes/60);
this
.setProperty("date_diff",hoursTotal.ToString());
}
}
return
this;

HTH

Sean



krish80 - Saturday, April 25, 2009 12:47 AM:

Sean Coleman,

Actullay my scenario is :

Two itemtype (2 forms). In first itemtype (form1) having some fields like serialno <sequance>, empname, dept, workstart_date, workend_date..... when the user (employee) going to feed the values, he will give his name and selecting his department & pick the workstart_date.... This time he will not select the workend_date. Now he will submit the values.

After some time he will reopen the same form and he will update his workend_date.

And some of the field values are also add to 2nd Itemtype (form2)

So when the user modify (update) the form1 then only we can get the workend_date. (But you have mention the below method for onBeforeUpdate) How the method will get the workend_date.


Now my Question is:

1. How to retrive & modify (update) the perticulare serialno,empname,workstart_date.... record in the 2nd Itemtype.

2. How to get the time difference & how to update this into 2nd itemtype field.


(pls give me sample method's also).


Regards,
RK



pallavig - Tuesday, July 26, 2011 5:56 AM:

It;s working good.

 

Thanks.