get previous month and year using Date functions

Posted on 2005-04-13
Last Modified: 2008-02-01
 I need to get Month and Year based on the following conditions.
if today is less than 20th of this month
then return deduct 5 months and return month as int and year (i.e 11, 2004)
else return deduct 4 months and return month as int and year (i.e 12, 2004)
and so on so forth.
Question by:BrijBhasin
    1 Comment
    LVL 33

    Accepted Solution

    check out the DateTime Class, you can do anything with this, pay particular attention to the .AddMonths(), .Day(), .Month() and .Year() methods.  You should be able to do what you want with those methods.

    Dim today as DateTime = DateTime.Now
    Dim return_day as DateTime

    If < 20 then
      return_day = today.AddMonths(-5)
      return return_day.Month.tostring & ", " & return_day.Year.tostring()
    End If

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now