首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

转换有关问题?

2012-01-26 
转换问题???dimstr_dtimeasdatestr_dtime2002-05-15我要得到的结果为是在月份后面加两个月/.得到为str_dt

转换问题???

  dim   str_dtime   as   date
    str_dtime   =   2002-05-15


我要得到的结果为是在月份后面加两个月/.
    得到为     str_dtime   =   2002-07-15

请问在vb中怎么实现哦

[解决办法]
Option Explicit

Private Sub Command1_Click()
Call MsgBox(Test( "2002-07-15 "))
End Sub

Private Function Test(ByVal strData As String) As String
Dim intMonth As Integer, intYear As Integer, intDay As Integer, strResult As String

intMonth = Month(CDate(strData))
intYear = Year(CDate(strData))
intDay = Day(CDate(strData))
strResult = IIf(intMonth + 2 > 12, intYear + 1 & "- " & intMonth + 2 - 12 & "- " & intDay, intYear & "- " & intMonth + 2 & "- " & intDay)
strResult = Format(strResult, "YYYY-MM-DD ")

Test = strResult
End Function

热点排行