Print date in Month name day, year format - vba

I'm looking to print the current date in Month name day, year format (example: October 3, 2014). I understand that I can get the current month in integer format with Month(Date) or Month(Now), but I want to know how I would output the current month in text format.

While waiting for nobody to answer this question I figured out that you can use the MonthName( number, [ abbreviate ] ) function to print the month name. As you can see from my example, the parameters of this function are number, which is a value from 1 to 12 representing the month, and abbreviate, which is an optional boolean. If this parameter is set to TRUE, it means that the month name will be abbreviated. If this parameter is set to FALSE or left out, the month name won't be abbreviated; now lets get back to answering the question.
Since Month(Date) returns the number of the month, you can set it as the first parameter of MonthName(); soMonthName(Month(Date))will return the name of the current month. You can then print the current date in the Month name day, year format with this code:MonthName(Month(Date)) & " " & Day(Date) & ", " & Year(Date)`.

Related

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")

VBA Run Macro Last Day of the Month

I want to return the last day in the month. The month is selected from a drop-down combo box. If I select January, this will return "1/31/2017" but I just want it to return 31. What am I missing?
EndDate = WorksheetFunction.EoMonth(ComboBox1.Value & Year(Date), 0)
The function WorksheetFunction.EoMonth returns a Date, while you want a numeric value representing the Day (of the last day of the month).
So you need a Long variable, and you can use the Day function.
EndDate = WorksheetFunction.EoMonth(ComboBox1.Value & Year(Date), 0)
Dim myDay As Long
myDay = Day(EndDate)

Date time functions help informix

How can I use the date add or date diff functions I have a scenario where I need find people whose birthdays are either today or after n number of days. How can I achieve it in informix.
SELECT mbr_code, fname, lname
INTO rsMbrCode, rsFName, rsLName
FROM asamembr
WHERE cust_code = membershipnumber
AND ((day(bdate) - day(CURRENT)) <= rsTest
AND MONTH(bdate) = month(CURRENT))
RETURN rsMbrCode, rsFName, rsLName WITH RESUME;
You could do something like this:
SELECT mbr_code,fname,lname
INTO rsMbrCode,rsFName,rsLName
FROM asamembr
WHERE cust_code = membershipnumber
AND MDY(month(bdate),day(bdate),year(today))
BETWEEN TODAY AND TODAY + <NUMBEROFDAYS> UNITS DAY;
You construct a date with Using MDY with the MONTH and DAY from bdate and YEAR from TODAY. Then you see if it is between the dates you want to match.
Documentation for MDY:
The MDY function takes as its arguments three integer expressions that
represent the month, day, and year, and returns a type DATE value.
The first argument represents the number of the month (1 to 12).
The second argument represents the number of the day of the month (1 to 28, 29, 30, or 31, as appropriate for the month)
The third expression represents the 4-digit year. You cannot use a 2-digit abbreviation.

QlikView Problems with Listbox

I want to have a list box that shows the following:
YYYY: WeekNumber - Date
The Date part is using a Broadcast Calendar (starts on Sundays, so week 1 of 2012 is actually Monday 12/26/2011).
This needs to be conditional:
If the year selected is the current year, only show through the latest "broadcastMonday" which in this case is Week 9 (2/20/2012). Then go back all the way through the prior year to week 1 of 2011, which is actually 12/27/2010.
If the year selected is less than the current year, only show all of that year plus all of the prior year.
The following expression for the List Box is working just fine for me with respect to displaying the right information, but when I click an item in the list it doesn't select it:
=If([Year]=year(ReloadTime()),if(left(BroadcastPeriod2,4)>=[Prior Year]
and BroadcastWeekStart2<ReloadTime(),(left(BroadcastPeriod2,4) & ' : ' &
BroadCastWeek2 & '-' & date(BroadcastWeekStart2)),),if(left(BroadcastPeriod2,4)>=
[Prior Year] and left(BroadcastPeriod2,4)<=([Year]),left(BroadcastPeriod2,4) & ' : '
& BroadCastWeek2 & '-' & date(BroadcastWeekStart2),))
I think the answer is to either do it in the load (concatenating the fields) or to use a table instead of the input box.
I would try to calculate the value for the listbox in the loadscript. I had trouble comparing StartMonth values in set analysis and could come around this by pre-calculating the values at load time.
Did something similar in Qlikview aggration with conditions