Get past 6 months MONTH in ref to TODAY - vba

Need help in displaying 6 month past month in refrence to todays date. E.g current month is June. below is the code, but is giving the as 1,I need to get January.
MsgBox ("Cheques would be checked for issue Month of " & (Month(Date)-5))

MsgBox ("your date is " & DateAdd("m", -6, Date()))

Related

Access Report Year should be change after April every Year

The session is starting from every year from April to March.
The report needs to publish in twice in that year first report in October and another in March.
In both conditions year will be 2019-20.
After March session will change then the year will also automatically changed 2020-21.
How to resolve it?
Below expression will not work on this condition:
Format(Date(),"yyyy-") & Right(Year(Date())+1,2)
That needs an adjustment to the fiscal year, which can be done like this:
=Format(Year(DateAdd("m",-3,Date()))*100+(Year(DateAdd("m",-3,Date()))+1) Mod 100,"0000-00")
This offsets the date of the fiscal year to match a pseudo calendar year, thus allowing you to extract year and month as for any calendar year. The first year is returned in full and multiplied with 100: 201900 and added to the decade part of the second year: 201900 + 20 = 201920. This is finally formatted to have a dash: 2019-20.
So reports between April 2019 and Mar 2020 should show 2019-20.
Use conditional IIf:
IIf(Month(Date()) < 3, Year(Date()) - 1 & "-" & Format(Date(),"YY"), Year(Date()) & "-" & Right(Year(Date()) + 1, 2))
Problem with using Date() to calculate this is if report for March is run on April 1, calculation will be wrong. Might be best to reference textbox on form for beginning year.

If using DateDiff function, using the interval "yyyy", is the function simply subtracting the difference between the year value of date1 and date2?

Macro does not appear to be taking days into account when calculating a person's age.
Sub alcohol_test()
Dim strBirthday As Date
strBirthday = CDate(InputBox("Input date of birth to be verified: ", "Date of Birth"))
If DateDiff("yyyy", strBirthday, Date) < 21 Then MsgBox ("Customer underage, sale of alcohol illegal.") _
Else MsgBox ("Age Confirmed: Alcohol may be sold")
End Sub
It is even worse:
When comparing December 31th to January 1st of the immediately succeeding year,
DateDiff for Year ("yyyy") returns 1, even though only a single day has elapsed, says Microsoft.
So you better compare two dates, e. g. if the birthday was before the day 21 years ago.
Dim datBirthday as Date
datBirthday = CDate(InputBox("Input date of birth to be verified: ", "Date of Birth"))
If datBirthday < DateSerial(Year(Date) - 21, Month(Date), Day(Date)) Then
I changed the variable name, as a beginning with "str" is a little misleading when you use date values.

Using VB to get 1st of July in previous year

I am trying to create a default date in SSRS using VB.
The date I am trying to create is the 1st of July in the previous year from the current year.
I am using something like this at the moment to get the current day in the previous year at 6am.
=CDate(Format(DateAdd("yyyy",-1,Now()), "yyyy-MM-dd") + " 06:00:00")
The expression to get 6pm of the 1st of July of the previous year is:
= Cdate(Cstr(Year(Today())-1) & "-07-01 06:00:00")
To get 6pm for the same date of the previous year
= Cdate(Cstr(Dateadd(DateInterval.year,-1,Today)) & " 06:00:00")

Get last day of previous quarter

DateAdd("m", -(Month(Date) - 1) Mod 3 - 1, Date)
This gives me 6/28/2015 while I need 20150630 . I can work on the format part but don't know how to get the last day of previous quarter instead of today's date of last quarter.
This should work for VBA. It just determines the first day of the current quarter and then subtracts one day.
Debug.Print DateAdd("q", DatePart("q", Date) - 1, "1/1/" & Year(Date)) - 1

VBA Excel autofilter for any date before the current month

I'm trying to filter a date column for any date that falls before the 1st of the current month.
So something similar to below:
ActiveSheet.Range("$A:$BF").AutoFilter Field:=12, Criteria1:= _
xlFilterYearToDate, Operator:=xlFilterDynamic
But doesnt include any dates in the current month it runs on.
Edit:
So any date that falls before the first of the current month, within the current year. If the filter was applied now, it would only show dates with the month of January 2015. If applied In August, only resulting visible dates should be anything within January-July 2015.
This should work for you:
Dim dtStart As Date
Dim dtFinal As Date
dtStart = CDate(Evaluate("DATE(YEAR(NOW()),1,1)"))
dtFinal = CDate(Evaluate("EOMONTH(TODAY(),-1)"))
ActiveSheet.Range("A:BF").AutoFilter 12, ">=" & dtStart, xlAnd, "<=" & dtFinal