我有个问题:
现在,我得到了一个主子项的日期范围(20160706-20160805),我必须将值分开并将其作为日期。我要做的是:
Main sub date ()
Dim strDaterage as string
Dim startdate as date
'For the sake of simplicity, just use the hard code for the date
strDaterange = "20160706-20160805"
startdate = findstartdate()
msgbox (startdate)
End sub
对于要分隔日期的函数,请提取值:
Function findstartdate()
daterange = "20160706-20160805"
startDateange = Left(daterange, 8)
startYear = Left(startDateange, 4)
startMonth = Mid(startDateange, 5, 2)
startDay = Right(startDateange, 2)
startdate = DateSerial(startYear, startMonth, startDay)
End Function
我尝试使用BYVAL和BYFER,但仍然无法正常工作。如何将日期值返回到主子目录中?
提前谢谢了!
不知道为什么要使用aString
作为输入,但是如果您愿意,可以使用下面的代码(有更有效的方法)。
您的子:
Sub SubDate()
Dim strDaterage As String
Dim startdate As Date
strDaterage = "20160706-20160805"
startdate = findstartdate(strDaterage)
MsgBox (startdate)
End Sub
您的功能:
' need to add a String variable as an input, and return tha value as a Date
Function findstartdate(DateRange As String) As Date
startDateange = Left(DateRange, 8)
startYear = Left(startDateange, 4)
startMonth = Mid(startDateange, 5, 2)
startDay = Right(startDateange, 2)
startdate = DateSerial(startYear, startMonth, startDay)
' convert the string result to a Date
findstartdate = CDate(startdate)
End Function
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句