# Determine if its a new month

I have an application that I need to determine if it is a new month, and if it is, it will automatically reset a 4 digit number to 0000.
Example: It is 11/17/2014, the 4 digit number is 1234.  On 12/1/2014 I need to the 4 digit number to be 0000.

I have been trying to write the code for it and I can not come up with a solution.  This is what I have come up with do far:
``````            If Now.AddDays((Now.Day - 1) * -1).AddMonths(1).AddDays(-1) >= DateTime.Now Then
casenumber = "0000"

End If``````

This does not work.  Any help on this would be greatly appreciated!!
Shaun Kline

membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.

Ok so we are so close!!  The only problem I am going to have with this is what if they do not use it on the 1st and they use it on the 2nd?  I think the only way around this is storing the current month that it was assigned and then comparing the 2.
Testing Shauns example:
``````Module Module1
Sub Main()
Console.WriteLine(String.Format("{0} and {1} are in the same month: {2}", Now, Now.AddDays(-1), CompareMonths(Now, Now.AddDays(-1))))
Console.WriteLine(String.Format("{0} and {1} are in the same month: {2}", New DateTime(2014, 11, 30), New DateTime(2014, 12, 1), CompareMonths(New DateTime(2014, 11, 30), New DateTime(2014, 12, 1))))
End Sub

Private Function CompareMonths(ByVal date1 As DateTime, ByVal date2 As DateTime) As Boolean
Return date1.Month = date2.Month
End Function
End Module``````

Produces the following output:
There is no need to store the date because you are using Now and Now.AddDays(-1).

-saige-

``DateDiff(DateInterval.Month, lastmonthassigned, DateTime.Now) >= 1``