Welcome! Log In Create A New Profile

Advanced

calculating dates

Posted by Joel 
Joel
calculating dates
March 14, 2009 11:04PM
Here's a newbie question for someone...

On a page I'm building, I have a "Start date" edit control, a combo box with numbers in it, another combo with "Days", "Weeks" ,"Months" & "Years" in it and a final "End Date" formatted field control. The date edit control is set up as a date control. I'm trying to do a simple calc based on the fields such that End date = Start date + "Combo 1 & 2" (read that as 1 month or 2 years, or whatever. Here's the code I've gotten to so far, I've actually spent an hour trying to figure this out but still don't have it yet. I'm kind'a in the middle of working with this and not sure where I left it. It just shouldn't be this hard! And the help files, manuals and tutorials don't really seem to help all that much. I feel like they expect you to already have some knowledge of the WebDev syntax and such.

//Convert date String to Programmable date format
dConvertedDate is Date
dConvertedDate = EDT_StartDate
dNewDate is Date
i is int



SWITCH (CMB_MembershipUnits)
CASE 2: dNewDate = dConvertedDate..Day + (CMB_MembershipDuration)

CASE 3: dNewDate = dConvertedDate..Day*7 + CMB_MembershipDuration

CASE 4: i = dConvertedDate..Month + CMB_MembershipDuration

CASE 5: dNewDate = dConvertedDate..Year + CMB_MembershipDuration
END

LIBF_EndDate = DateToString(dNewDate)
DerekT
Re: calculating dates
March 15, 2009 12:12PM
Joel
I would add a new variable to hold the value to be added.

Assuming you have set the Start date and selected the Duration.
Run the procedure from the Row Selection of CMB_MembershipUnits.
PROCEDURE lpSetEndDate()

dNewDate = edt_StartDate //Reset in case of unit change

SWITCH CMB_MembershipDuration
	CASE 2: //Day
		nUnitsToAdd = CMB_MembershipUnits..DisplayedValue
		dNewDate..Day += nUnitsToAdd
	CASE 3: //Week
		nUnitsToAdd = Val(CMB_MembershipUnits..DisplayedValue) * 7
		dNewDate..Day += nUnitsToAdd
	CASE 4: //Month
		nUnitsToAdd = CMB_MembershipUnits..DisplayedValue
		dNewDate..Month += nUnitsToAdd
	CASE 5: //Year
		nUnitsToAdd = CMB_MembershipUnits..DisplayedValue
		dNewDate..Year += nUnitsToAdd
END

edt_EndDate = dNewDate //Display calculated date
You may need a similar Procedure called from the CMB_MembershipUnits in case the unit type is changed.
Depends pretty much on what control you build into the selection process.
If it were me then I would have any change/selection in the CMB_MembershipUnits reset
edt_EndDate, dNewDate and nUnitsToAdd and fill CMB_MembershipDuration with an appropriate number range.....Day 1 - 31, Week 1 - 52, Month 1 - 12, Year 1 - ????

This of course assumes that I understood what is was that you were trying to achieve.
Hope it helps, regards

DerekT
Joel
Re: calculating dates
March 15, 2009 04:10PM
Derek -

Thanks much - that's exactly what I needed!

J
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: