[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

get previous month and year using Date functions

HI,
 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.
0
BrijBhasin
Asked:
BrijBhasin
1 Solution
 
raterusCommented:
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.  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDateTimeClassTopic.asp

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

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now