Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Casl Macro Help

Status
Not open for further replies.

Computer8822

Programmer
Aug 7, 2008
20
0
0
I was wondering if there was a way to get the current date and add a couple months to it?
 
Here's the function I use to accomplish that:

Code:
Function CalcDate() AS String
'******************************************************************************
' Calculate Sixty days from today's date                                       
'******************************************************************************
	    sixtydays=CVar(Date)+60
        sixtydays=Format(sixtydays,"MMddyy")
        CalcDate=sixtydays
End Function

Not much to it... That should get you on the right track.
 
As the code provided by Deception contains functions not in the Casl language i'd use something like the following.
Code:
--Forward Declarations
Func CurDate Returns String forward
Func AddTwoMonths(dateString) Returns String Forward

--add two months to todays date and alert user
--i use system to get todays date so I do not need to handle errors
--if user provided date check for validity prior to functions or update the functions

alert AddTwoMonths(curDate),ok

--forwarded functions, they do not need to be forwarded if placed at the begining of code rather than end
--my pref is at the end of the script
Func AddTwoMonths(dateString) Returns String
	String myDay, myMonth, myYear, returnDate

	myDay = Mid(dateString,3,2)
	myMonth = Left(dateString,2)
	myYear = Right(dateString,4)

	If Val(myMonth) < 11 Then{
		myMonth = Right("0"+ Str(Val(myMonth) + 2),2)
	}Else{
		If myMonth = "11" Then myMonth = "01"
		If myMonth = "12" Then myMonth = "02"
		myYear = Str(Val(myYear)+1)
	}

	Case myMonth Of
		"02": If Val(myDay) > 28 Then myDay = "28" -- also needs some leap year consideration i am to lazy to add
		"04": If Val(myDay) > 30 Then myDay = "30"
		"09": If Val(myDay) > 30 Then myDay = "30"
	EndCase
	
	Return  myMonth+myDay+myYear
EndFunc

Func CurDate Returns String 
	--returns todays date in MMDDYYYY format
	String myDay, myMonth, myYear, returnDate
	
	--pad month and day for format MM DD
	myMonth = Right("0"+Str(CurMonth),2)
	myDay = Right("0"+Str(CurDay),2)
	--depending on system settings short year may or may not be issue 
	If Length(Str(CurYear))=2 then{
		--needs adjusted if use in year 2100, if still using casl language then I pity you lol
		myYear = "20"+Str(CurYear)
	}Else{
		myYear = Str(CurYear)
	}

	Return myMonth + myDay+ myYear
EndFunc

[small]Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black[/small]
 
line in Func AddTwoMonths t needed and should be deleted
Code:
"04": If Val(myDay) > 30 Then myDay = "30"
would only be hit if you added two months to Feb 31st which would never happen.

[small]Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top