Computer8822
Programmer
- Aug 7, 2008
- 20
I was wondering if there was a way to get the current date and add a couple months to it?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Function CalcDate() AS String
'******************************************************************************
' Calculate Sixty days from today's date
'******************************************************************************
sixtydays=CVar(Date)+60
sixtydays=Format(sixtydays,"MMddyy")
CalcDate=sixtydays
End Function
--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
"04": If Val(myDay) > 30 Then myDay = "30"