tags:

views:

65

answers:

5

Hi, Can u give me a simple function in vb.net which can take number of days and date as parameters and subtract these number of days from given date. Forexample

Private function Calculate(Byval p_number_days,p_date) as date

 Dim calculated_date as Date= (p_date) - (p_number_days) 
 return calculated


End Function
+2  A: 
Private Function Calculate(ByVal p_Number_Days As Integer, ByVal p_Date As DateTime) As DateTime
    Return p_Date.AddDays(p_Number_Days * -1)
End Function
Joel Coehoorn
A: 

Just use the AddDays() method of the DateTime class - MSDN

It can take a negative value as well as positive.

AdamRalph
A: 

You'll have to excuse me, I haven't used VB in a long time, so some syntax might be wrong.

Private Function Calculate(p_days AS Integer, p_date AS Date) AS Date
  Return p_date - TimeSpan.FromDays(p_days)
End Function
Ray Hidayat
A: 

If you can, always represent number of days as a TimeSpan. It makes the code look much nicer.

Private function Calculate(Byval p_number_days as TimeSpan,p_date as Date) as date
    Return p_date - p_number_days
Jonathan Allen
A: 

Thanks all of you,it worked