Previous Month Function

Posted on 2005-05-02
Last Modified: 2010-04-23
I want to include in my program a function that will give me the previous month in the folowing format "MMM" or "APR".
I want to use this to include in a file name ex.   APR EOM - Outage Report.pdf

Is there a function in that will do this or is there a way to minus one from mydate(Now, "MMM") to do this??
Question by:mikevere
    LVL 96

    Accepted Solution

       Dim lastMonth As String = DateTime.Now.AddMonths(-1).ToString("MMM")

    LVL 7

    Expert Comment

    Format(Now.AddMonths(-1), "MMM")
    LVL 24

    Expert Comment

    by:Jeff Certain
    You can use DatePart(DateInterval.Month, DateAdd(DateInterval.Month, -1, myDate)) to get the integer representing the previous month.
    LVL 96

    Expert Comment

    by:Bob Learned
    Dog pile :))

    LVL 24

    Expert Comment

    by:Jeff Certain
    Yeah... it's a shame the date/time stamp doesn't show seconds ;)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    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.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 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

    14 Experts available now in Live!

    Get 1:1 Help Now