How to add No. Of Days to SmartDate ?

How to add No. Of Days to SmartDate ?

Old forum URL: forums.lhotka.net/forums/t/5896.aspx


Mandar C. Jambotkar posted on Thursday, November 27, 2008

Hi,

I have some properties which I'll be using for periods, i.e. User will select some respective date (From_Date) and I want to change the (To_Date) for respective period selected.

Now this "Period" can be "Weekly" / "Fortnightly" / "Monthly".

Hence I want to add 7, 15 or 30 days respectively to the From_Date field to generate To_Date.

Please guide me through to handle it using smartdate.

Thanks !

 

 

 

 

Marjon1 replied on Friday, November 28, 2008

The smart date object has a date property which you could then use the standard add functions to add the number of days and get a new date. I'm assuming the To_Date field cannot be set unless the From_Date value actually has a value.

Assuming your To_Date field is populate when you set the period property, you could have good like this in your setter.

If Not _FromSmartDate.IsEmpty() Then
_ToDate = new SmartDate(_FromSmartDate.Date.Add("d", _periodvalue))
End if

Apologies for any silly mistakes in code, it's late and I'm too lazy to confirm in VS! :)

Mandar C. Jambotkar replied on Sunday, November 30, 2008

'Below samples are for adding Days and Months to current date respectively.

If Not _weekPaysFromDate.IsEmpty Then

_weekPaysToDate = New SmartDate(_weekPaysFromDate.Date.AddDays(6))

End If

 

If Not _monthlyPaysFromDate.IsEmpty Then

_monthlyPaysToDate = New SmartDate(_monthlyPaysFromDate.Date.AddMonths(1))

End If

 

Marjon, Thank you so much for your help !!!

You sent me a hint even though it was late night, thanks again !

RockfordLhotka replied on Monday, December 01, 2008

In CSLA 3.6 you should be able to directly do date math with a SmartDate object. It might even work in 3.5. The reason is that I've added in a lot of type conversion code so .NET is better able to treat a SmartDate as a DateTime when necessary.

Copyright (c) Marimer LLC