# From Date and To date calculation

**URL:** <https://www.dynamicsuser.net/t/from-date-and-to-date-calculation/31931>\
**Category:** Technical Forum\
**Created:** [July 19, 2011, 8:11am UTC](https://www.dynamicsuser.net/t/from-date-and-to-date-calculation/31931 "2011-07-19T08:11:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ven\_BenZ](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Ven\_BenZ](https://www.dynamicsuser.net/u/Ven_BenZ)\
**Post date:** [July 19, 2011, 8:11am UTC](https://www.dynamicsuser.net/t/from-date-and-to-date-calculation/31931/1 "2011-07-19T08:11:44Z")

</div>

if(this.fromdate && (this.todate \>\> this.fromdate))  
{  
This.reqdays = any2str(this.todate- this.fromdate);  
}  
Else  
{  
Throw error (“Todate must be grater than fromdate”);  
}

above code is not working  
can u plz guide me!!!

---

<div class="post-metadata">

**Author:** ![kollinaresh.k](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@kollinaresh.k](https://www.dynamicsuser.net/u/kollinaresh.k)\
**Post date:** [July 19, 2011, 8:30am UTC](https://www.dynamicsuser.net/t/from-date-and-to-date-calculation/31931/2 "2011-07-19T08:30:45Z")

</div>

Hi Ven Benz,

try this…

static void Job19(Args \_args)  
{  
TransDate fromDate,toDate;  
int reqDays;  
;

fromDate = mkdate(01,07,2011);  
toDate = mkdate(19,07,2011);

if(fromDate && (toDate \> fromdate))  
{  
reqDays = todate - fromDate;  
}  
else  
{  
throw error(strfmt(“To-date %1 must be greater than from-date %2”,todate,fromdate));  
}  
info(strfmt("%1",reqDays));  
}

Naresh Kolli

---

<div class="post-metadata">

**Author:** ![Ven\_BenZ](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Ven\_BenZ](https://www.dynamicsuser.net/u/Ven_BenZ)\
**Post date:** [July 19, 2011, 9:47am UTC](https://www.dynamicsuser.net/t/from-date-and-to-date-calculation/31931/3 "2011-07-19T09:47:02Z")

</div>

this.RequestedFromTime = timenow();

if(this.RequestedToDate && (this.RequestedToDate \>this.RequestedFromDate ))

{

this.RequestedDays = this.RequestedToDate - this.RequestedFromDate;

}

else

{

throw error("To-date must be greater than from-date ");

}

In above code I am first entering this.RequestedFromDate the next step its showing error with out entering RequestedToDate

---

<div class="post-metadata">

**Author:** ![kollinaresh.k](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@kollinaresh.k](https://www.dynamicsuser.net/u/kollinaresh.k)\
**Post date:** [July 19, 2011, 11:12am UTC](https://www.dynamicsuser.net/t/from-date-and-to-date-calculation/31931/4 "2011-07-19T11:12:09Z")

</div>

Hi Ve Benz,

You are giving only the this.RequestedFromTime,but in the if coniditon you are checking for the this.RequestedToTime…so if it is not it obviously shows the error…If this is case you need to give the RequestedToTime also…

If this is not the case, can you can explain it in details…

Naresh Kolli

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [July 19, 2011, 5:36pm UTC](https://www.dynamicsuser.net/t/from-date-and-to-date-calculation/31931/5 "2011-07-19T17:36:40Z")

</div>

Where you have placed this code?

---

<div class="post-metadata">

**Author:** ![Ven\_BenZ](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Ven\_BenZ](https://www.dynamicsuser.net/u/Ven_BenZ)\
**Post date:** [July 20, 2011, 6:35am UTC](https://www.dynamicsuser.net/t/from-date-and-to-date-calculation/31931/6 "2011-07-20T06:35:38Z")

</div>

i wrote the code in Table level modifiedfield method

now i changed code

if(this.ApprToDate && this.ApprToDate \< this.ApprFromDate)

{

throw error(“ApprFromDate Must be greater than ApprFromDate”);

}

if(this.ApprToDate && this.ApprToDate \> this.ApprFromDate)

{

this.ApprovedDays = this.ApprToDate - this.ApprFromDate;

}

like this its working now

thanks for replays

thanQ;
