一个月不是特别的工作日,而是相反 [英] NOT Particular Weekday in a Month but the opposite

查看:96
本文介绍了一个月不是特别的工作日,而是相反的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的代码告诉我(今天)4月12日是本月的第二个

。我唯一能找到的是

的功能告诉我在给定的月份和年份中哪一天属于第二天。


请帮助

问候

ScuBart

I want my code to tell me that (today) April 12th is the second
wednesday of the month. And only thing I can find is the function to
tell me what date belongs to the 2nd day in a given month and year.

Please help
regards
ScuBart

推荐答案

你必须写一个函数去做吧。做类似的事情......


1.获取当月第一天的日期。

2.查找两个日期之间的周数

3.然后就可以得到星期三的数量或

无论如何。


查找DateAdd, DateDiff,MOD,应该这样做。

you''d have to write a function to do it. Do something like...

1. get the day of the first day of the month.
2. find the number of weeks between the two dates
3. then from that you should be able to get the number of Wednesdays or
whatever.

Look up DateAdd, DateDiff, MOD, and that should do it.


在标准代码模块中植入此代码。将鼠标光标放在someSub()内部
。按F5键。这将显示给定日期

,内置Date()函数返回,如果它是第1,第2,

第3 ......当天出现那个月。您可以使用任何日期值

作为参数。


''------------------ ------------------------------------

Sub someSub()

Dim d1作为日期,arrSuffix作为变体

arrSuffix = Array(""," 1st","""""""""""'4th" ,5)

d1 =日期'' - d1可以是你想要的任何日期:d1 =#3/13/06#

Debug.Print arrSuffix (DayOfMonthCount(d1))& " " &安培; _

WeekdayName(工作日(d1))

结束子

函数DayOfMonthCount(d1作为日期)作为整数

Dim i As Integer,j As Integer,k As Integer,d2 As Date

d2 = d1 - Day(d1)+ 1'' - 从d1开始

k = 0

'' - d1个月的天数

j =天(DateAdd(" m",1,d1) - Day( DateAdd(" m",1,d1)))

对于i = 0到j

'' - 计算当月d1天发生的次数如果d2 + i> d1然后退出给

下一页

DayOfMonthCount = k

结束功能

''------ ----------------------------------------------


Rich


***通过Developersdex发送 http://www.developersdex.com ***
Plant this code in a standard code module. Place your mouse cursor
inside of someSub(). Press the F5 key. This will display the given day
which the built-in Date() function returns and if it is the 1st, 2nd,
3rd... occurence of that day in that month. You can use any date value
for the argument.

''------------------------------------------------------
Sub someSub()
Dim d1 As Date, arrSuffix As Variant
arrSuffix = Array("", "1st", "2nd", "3rd", "4th", "5th")
d1 = Date ''--d1 can be any date you want: d1=#3/13/06#
Debug.Print arrSuffix(DayOfMonthCount(d1)) & " " & _
WeekdayName(Weekday(d1))
End Sub
Function DayOfMonthCount(d1 As Date) As Integer
Dim i As Integer, j As Integer, k As Integer, d2 As Date
d2 = d1 - Day(d1) + 1 ''--go to beginning of d1
k = 0
''--get count of days in the month of d1
j = Day(DateAdd("m", 1, d1) - Day(DateAdd("m", 1, d1)))
For i = 0 To j
''--get count of times the d1 day occurs in the month of d1
If Weekday(d2 + i) = Weekday(d1) Then k = k + 1
If d2 + i > d1 Then Exit For
Next
DayOfMonthCount = k
End Function
''----------------------------------------------------

Rich

*** Sent via Developersdex http://www.developersdex.com ***


Rich,

我可能需要一点点帮助。我已经将代码放在一个模块中,并从

Visual Basic编辑器中逐步完成它。我已经把一个msgbox放到了
,看看结果是什么,它说今天是第二个星期五

(而不是星期四)但是这有事情要做星期一是我的

第一天,正常是星期天。


现在;当我打开一个表格时,我会显示日期,周数和

子表格中属于这个给定日期或日期的行为。


我们有每个星期一的行动和每个星期一(星期三和星期四)的第一个星期一的行动。因此,当我打开表单时,我会

必须将函数放入文本框中,例如,如果这个

是第二个星期一(或周三或星期四)。


你能给我额外的提示吗?

到目前为止感谢

Rich,
I may need a little bit of help. I''ve put the code in a module and from
the Visual basic Editor I can step through it. I''ve put in a msgbox to
see what the result is and it says that today is the second friday
(instead of thursday) but that has something to do with monday being my
first day and normal is sunday.

Now; when I open een a form I display the date, the weeknumber and in a
subform the actions that belong to this given date or day.

We have actions on every monday and actions for the first monday of the
month (and wednesdays and thursday to). So When I open the form I''ll
have to caal the function to put in to a text box for example if this
is the second monday (or wednesday or thursday).

Can you provide me with extra hints!
Thanks so far


这篇关于一个月不是特别的工作日,而是相反的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆