0

I want to make a school fees collection system, but I am confused about dates. I want it like this:

Count the months From Admission date to now.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
Sajjad Ali
  • 23
  • 6
  • 1
    "Count the months" is actually fairly hard to do. If admission was `2000-01-01` and now is `2000-02-29`, how many months is that? How many months is it if now is `2000-03-15`? What about if admission is `2000-02-29` and now is `2000-03-01`? And is it any different if admission is `2000-01-01` and now is `2000-01-30` versus `2000-02-01` and `2000-03-01` (they're both 30 days) ? – Caius Jard Oct 02 '20 at 19:18
  • You can do something like: `dim admissionDate = new DateTime(2020, 9, 15) dim diff = Date.Now.Subtract(admissionDate).Days / 30.45F dim months = Math.Truncate(diff) dim days = 30.45F * (diff - months)` (where `30.45F` is the *medium compensated average* -> I've just made it up, but it's the average days in a month compensated for leap years. It's *relatively* precise :). For a *less precise* measure: `dim months = ((Date.Now.Year - admissionDate.Year) * 12) + Date.Now.Month - admissionDate.Month`. – Jimi Oct 02 '20 at 19:45
  • The first will give you `0` month, `14` days and decimal hours, the latter `1` month. – Jimi Oct 02 '20 at 19:54
  • Does this answer your question? [Calculating Number of Months between 2 dates](https://stackoverflow.com/questions/3249968/calculating-number-of-months-between-2-dates) – Ruud Helderman Oct 02 '20 at 20:17
  • Nope. I just want to my program to increase a value if a certain month increased for example: 2020,9,15 is my date of admission and when the actual date come next month like : 2020,10,15 a label should appear next to student name Caption would be DUE FEES. – Sajjad Ali Oct 03 '20 at 03:58
  • The you probably just need `dim pastDue = Date.Now.AddMonths(-1) >= admissionDate` – Jimi Oct 03 '20 at 08:03

1 Answers1

0

I used the DateDiff function described here https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.dateandtime.datediff?view=netcore-3.1

From the docs...

"The return value for DateInterval.Month is calculated purely from the year and month parts of the arguments."

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim Date1 = #10/2/2020#
    Dim Date2 = #12/25/2024#
    Dim DifInMonths = DateDiff(DateInterval.Month, Date1, Date2)
    Debug.Print(DifInMonths.ToString)
End Sub
Mary
  • 14,926
  • 3
  • 18
  • 27