473,624 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to code a VBA procedure that outputs the date of every Monday of the year?

8 New Member
I need a vba procedure that outputs the the date of every monday of the year. The output would look like

01/03/2011
01/10/2011
01/17/2011
.
.
.
12/26/2011

Any help would be greatly appreciated.
Dec 2 '10 #1
11 3502
mshmyob
904 Recognized Expert Contributor
What have you tried so far?

A hint if you haven't even attempted anything is to create a loop through all days starting with Jan 1, 2011 and ending on Dec 31, 2011. As you loop through then use the WEEKDAY function on each date.

Try it and post back your code if you have any problems.

cheers,
Dec 2 '10 #2
hype261
207 New Member
A more efficient method would be to start on 01 January of what ever year and find the first Monday of the year. All the other Mondays are going to be 7 days for there.
Dec 3 '10 #3
mshmyob
904 Recognized Expert Contributor
I can't really see there being much if any of a performance (ie: efficiency) difference between using the Weekday function over the Dateadd function but each to there own.


cheers,

PS. - Now that I think about it you may be right. Both solutions would need to use the Dateadd function but mine would also add the step of using the Weekday function each iteration where yours would use it for a maximum of 7 iterations. Even though the performance issue would not be noticable on just 365 iterations I believe yours should be the way to go.
Dec 3 '10 #4
NeoPa
32,566 Recognized Expert Moderator MVP
More than that we won't do for you until you show that you have attempted this yourself first. We are not a free coding service. We are here to help with answers to questions - not to do your work for you.
Dec 5 '10 #5
ADezii
8,834 Recognized Expert Expert
I think the whole efficiency angle is a mute point, since, using a combination of the Weekday() and DateAdd() Functions, over 10 trials, took an Average of 22 Milliseconds to execute (extracting Mondays between the Range 1/1/2011 and 12/31/2011.

P.S. - I know, too much time on my hands! (LO(L).
Dec 5 '10 #6
mshmyob
904 Recognized Expert Contributor
That is what I was saying about there being no performance difference but I will concede the point that hype's method might be slightly better in the sense of coding effieciency.

cheers,
Dec 5 '10 #7
ADezii
8,834 Recognized Expert Expert
Yep, hype261's more efficient approach took an Average of 15.5 Milliseconds as opposed to 22 over 10 Trial Runs.
Dec 5 '10 #8
NeoPa
32,566 Recognized Expert Moderator MVP
This is actually a good point (It deserves consideration). Both points in fact.
  1. It is important when looking at a project to bear in mind the real impact of a decision. 22 ms (or about 1/500 second) will not be noticeable to anybody using a project.
  2. Efficiency of code is always worth striving for. Even when the difference isn't noticeable. Getting an understanding of what is efficient and what is untidy is always worth having. It is particularly important when the same code is run over and again within other code. A routine taking 20 ms (1/500 second) extra won't have too much of an effect when run once, but when it is run for every record of a 500 thousand recordset, then it starts to be significant (1,000 seconds = 16 minutes).

So, know how much of an impact something makes, but also try to code as cleanly and efficiently as possible anyway. The attitude will probably pay dividends later on in situations where it may make more of a difference.
Dec 5 '10 #9
NeoPa
32,566 Recognized Expert Moderator MVP
ADezii:
Yep, hype261's more efficient approach took an Average of 15.5 Milliseconds as opposed to 22 over 10 Trial Runs.
Far, FAR, too much time on your hands clearly :-D
Dec 5 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4196
by: Chumley the Walrus | last post by:
I'm trying to use DatePart and Datediff functions to show the formatted m/dd/yyyy display for the dates of Monday and Friday of the current week. I want it to display as: Our Weekly Schedule 8/23/2004 thru 8/27/2004: Can't pinpoint the parameter to check for the current week. Is there a good reference anywhere to show how to use the methods and such of both datepart and datediff, or has anyone programmed something similar prior.
6
9440
by: phforum | last post by:
If user input the date is 2006-07-01. How to convert it to last year 2005-07-01? Thanks
0
1527
by: chrislearner | last post by:
Hi All, I am new to this group and urgently require help from you guys!! I have to hard code the START date and the END date to 04/01/2006 and 06/30/2006 respectively. Here's the existing sql code where I need to do the changes. SET XL_END = (SELECT Month_End_Date FROM dba.Cycle_Date); SET XL_START = dba.Get_Dynamic_Date('Current_Month_Begin',XL_END); SET XL_INCUR = DATEADD(YEAR,-2,XL_START);
3
1115
by: mibbsin | last post by:
Hi all !!!! I am a new bee for programming, my question may be simple but i dont know how to do it...My senario is I have four column named DISCOUNT CODE, DATE ACTIVATED, DATE DEAVTIVATE, IS ACTIVE... So when i use the DISCOUNT CODE the DATE ACTIVATED should be todays date and the DATE DEACTIVATE should be exactly one year from the date activated...and in the IS ACTIVE column the value should be 1 untill the code is active....and after one year...
4
1309
by: iniyan | last post by:
hi guys i'm new for asp.i tried to search for dropown box with date,year and month where calender attached together.but can't find.anyone can help me get the source code or let me know where to find.thanx guys adios iniyan
2
3294
by: shapper | last post by:
Hello, I am checking a DateTime variable to check if in range: low < MyDateTime < high. However, I know need do the same but not care about the year. Can I do this? Thanks, Miguel
5
4325
by: abhishekmoon007 | last post by:
the program should accept the current date, month and year and should calculate 1 year later date.
1
6018
by: ejrtree15 | last post by:
i am new to java and programming all together. any help would be appreciated. i need to get it to input the date as so: mm/dd/yyyy and then output the date as so: February 29, 2004 is a date in a leap year. and if the date was before the year 1582 it leaves the date as it was entered: mm/dd/yyyy i know that i need to use a switch statement. but i am lost right now. im not sure if i have the variables set right or if i even need the...
0
1952
by: suvarn sawant | last post by:
I have written jsp code to insert date in oracle but its giving error null.my code is: String query="insert into test_KMS_DATA_ROW values('"+rocode+"','"+roname+"',"+activityId+",'"+activity+"',"+duration+",to_date("+startdate+",MM/DD/YYYY HH24:MI:SS),'"+starttime+"',to_date("+enddate+",MM/DD/YYYY HH24:MI:SS),'"+endtime+"','"+startby+"','"+endby+"','"+d+"','N')"; stmt1=con.createStatement(); int n=stmt1.executeUpdate(query);
0
8236
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8173
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8679
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8475
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7159
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.