Hello,

I have 2 objects:
objContract.activeon and objContract.expireson.

I am trying to add 364 days to objContract.activeon and assign it to the value
of objContractexpireson.

----------------------------------------------------------
// Contract Start Date
DateTime dt = DateTime.Now;
objContract.activeon = new CrmDateTime();
int iFound = 0;
string sTemp = "";

if (objAccount.paymenttermscode.Value == 1) // due on receipt - use Todays
Date
{
objContract.activeon = objInvoice.CFDinvoicedate;
}
else // use Inv Date
{
objContract.activeon.Value = dt.ToString("s");
}
iFound = objContract.activeon.Value.IndexOf("T");
sTemp = objContract.activeon.Value.ToString().Substring(0, iFound);
MyContractArray.Add(sTemp);


// Contract End Date (expireson)(date) (364 days from active on date)
objContract.expireson = objContract.activeon + 364 Days ?
MyContractArray.Add(objContract.expireson.Value.ToString());

RE: C# Adding Days to a Date by DavidJennaway

DavidJennaway
Fri May 25 17:00:00 CDT 2007

I'm not sure what all your codes is doing (e.g. the MyContractArray), but the
easiest option is to convert the fields to instances of the .Net DateTime
class and use the AddDays method.

DateTime dtActive = DateTime.Parse(objContract.activeon.Value);
DateTime dtExpires = dtActive.AddDays(364);
objContract.expireson.Value = dtExpires.ToString("s");


--
David Jennaway - Microsoft Dynamics CRM MVP
Web: http://www.excitation.co.uk


"kathyc" wrote:

> Hello,
>
> I have 2 objects:
> objContract.activeon and objContract.expireson.
>
> I am trying to add 364 days to objContract.activeon and assign it to the value
> of objContractexpireson.
>
> ----------------------------------------------------------
> // Contract Start Date
> DateTime dt = DateTime.Now;
> objContract.activeon = new CrmDateTime();
> int iFound = 0;
> string sTemp = "";
>
> if (objAccount.paymenttermscode.Value == 1) // due on receipt - use Todays
> Date
> {
> objContract.activeon = objInvoice.CFDinvoicedate;
> }
> else // use Inv Date
> {
> objContract.activeon.Value = dt.ToString("s");
> }
> iFound = objContract.activeon.Value.IndexOf("T");
> sTemp = objContract.activeon.Value.ToString().Substring(0, iFound);
> MyContractArray.Add(sTemp);
>
>
> // Contract End Date (expireson)(date) (364 days from active on date)
> objContract.expireson = objContract.activeon + 364 Days ?
> MyContractArray.Add(objContract.expireson.Value.ToString());
>
>
>
>

Re: C# Adding Days to a Date by GrandiJoos

GrandiJoos
Wed May 30 05:17:04 CDT 2007

I think you need to consider leap-years.
The code above then becomes:

DateTime dtActive = DateTime.Parse(objContract.activeon.Value);
DateTime dtExpires = dtActive.AddYears(1); //set to same date next
year
DateTime dtExpires = dtExpires .AddDays(-1); //and go one day back
objContract.expireson.Value = dtExpires.ToString("s");

PS I did not test the code but it looks alright ;)

GrandiJoos

On 26 mei, 00:00, David Jennaway
<DavidJenna...@discussions.microsoft.com> wrote:
> I'm not sure what all your codes is doing (e.g. the MyContractArray), but the
> easiest option is to convert the fields to instances of the .Net DateTime
> class and use the AddDays method.
>
> DateTime dtActive = DateTime.Parse(objContract.activeon.Value);
> DateTime dtExpires = dtActive.AddDays(364);
> objContract.expireson.Value = dtExpires.ToString("s");
>
> --
> David Jennaway - Microsoft Dynamics CRM MVP
> Web:http://www.excitation.co.uk
>
> "kathyc" wrote:
> > Hello,
>
> > I have 2 objects:
> > objContract.activeon and objContract.expireson.
>
> > I am trying to add 364 days to objContract.activeon and assign it to the value
> > of objContractexpireson.
>
> > ----------------------------------------------------------
> > // Contract Start Date
> > DateTime dt = DateTime.Now;
> > objContract.activeon = new CrmDateTime();
> > int iFound = 0;
> > string sTemp = "";
>
> > if (objAccount.paymenttermscode.Value == 1) // due on receipt - use Todays
> > Date
> > {
> > objContract.activeon = objInvoice.CFDinvoicedate;
> > }
> > else // use Inv Date
> > {
> > objContract.activeon.Value = dt.ToString("s");
> > }
> > iFound = objContract.activeon.Value.IndexOf("T");
> > sTemp = objContract.activeon.Value.ToString().Substring(0, iFound);
> > MyContractArray.Add(sTemp);
>
> > // Contract End Date (expireson)(date) (364 days from active on date)
> > objContract.expireson = objContract.activeon + 364 Days ?
> > MyContractArray.Add(objContract.expireson.Value.ToString());