函数情况
getdate( thisdate,betweendate)
{
   ……………
   return olddate;
}thisdate:现在的日期,或任意一个日期。
betweendate: thisdate的前 多少 天。
olddate: 前多少天的日期需要处理跨月份的问题

解决方案 »

  1.   

    不用写函数,直接计算就行:olddate=thisdate-betweendate
      

  2.   

    Public Function GetDate(thisDate As Date, betweenDate As Integer) As Date
        GetDate = DateAdd("d", betweenDate, thisDate)
    End Function如果betweenDate<0,则就是计算前面多少天的日期。
    可以使用 DateAdd 函数对日期加上或减去指定的时间间隔。例如,可以用 DateAdd 来计算距今天为三十天的日期;或者计算距现在为 45 分钟的时间。为了对 date 加上“日”,可以使用“一年的日数” (“y”),“日” (”d”) 或“一周的日数” (”w”)。DateAdd 函数将不返回有效日期。在以下实例中将 1 月31 日加上一个月:DateAdd(m, 1, 31-Jan-95)
    结贴吧。
      

  3.   

    可以使用 DateAdd 函数对日期加上或减去指定的时间间隔。
      

  4.   

    DateDiff 函数可用来决定两个日期之间所指定的时间间隔数目。例如,可以使用 DateDiff 来计算两个日期之间相隔几日,或计算从今天起到年底还有多少个星期。
    Private Sub Command2_Click()
    Dim TheDate As Date  
    Dim Msg
    TheDate = InputBox("Enter a date")
    Msg = "Days from today: " & DateDiff("d", Now, TheDate)
    MsgBox Msg
    End Sub