Reputation:
I've got a very simple program:
Option Strict On
Imports System
Imports Microsoft.VisualBasic
Module Program
Sub Main(args As String())
Dim birthDate As DateTime = DateTime.Now.AddYears(-1)
Dim dateDifference As DateTime = DateDiff(DateInterval.Month, DateTime.Now, birthDate)
Console.WriteLine(dateDifference.ToString)
Console.ReadLine()
End Sub
End Module
Trying to use DateDiff
gives me the error "DateDiff is not declared. It may be inaccessible due to it's protection level." Everything I have looked at says that DateDiff
should be in the Microsoft.VisualBasic
namespace. I've imported that namespace as you can see. I even added a reference to it in the Solution Explorer. Very frustrating, will someone please let me know what I'm doing wrong?
Upvotes: 0
Views: 941
Reputation: 12804
You had two problems in your code
Sub Main(args As String())
Dim birthDate As DateTime = DateTime.Now.AddYears(-1)
Dim dateDifference As Long = DateDiff(DateInterval.Month, DateTime.Now, birthDate)
Console.WriteLine(dateDifference.ToString)
Console.ReadLine()
End Sub
Upvotes: 1
Reputation: 581
Option Strict On
Imports System
Imports Microsoft.VisualBasic
Module Program
Sub Main(args As String())
Dim birthDate As DateTime = DateTime.Now.AddYears(-1)
Dim dateDifference As Long = DateDiff(DateInterval.Month, DateTime.Now, birthDate)
Console.WriteLine(dateDifference.ToString)
Console.ReadLine()
End Sub
End Module
This works.
Upvotes: 1