Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Is this possible?

Posted on 2014-03-26
10
115 Views
Last Modified: 2014-03-31
I've built a calendar function that mimics the iPhone set up as far as being able to schedule recurring events. I've got "every day, every week, every two weeks, every month and every year."

To do this, I'll just start with the initial date and add whatever timeframe is needed. No biggie.

My client wants an option where they can schedule something on every third Wednesday of the month. Initially, I thought I would just add a "add 21 days" to the scheduling dynamic, but I knew intuitively this wouldn't work because not every month is 30 days. Consequently, I get the "third Wednesday" scenario happening on Wednesday then Friday etc.

My first reaction was to tell the client that the amount of coding to do what they're attempting would be significant just because you're having to anticipate every month and then the way the dates will shift from year to year.

But am I off? Is there a way to schedule "every third Wednesday?" If so, I'd love to get some feedback as to how to write that code. If I am thinking correctly, as far as telling them that they're asking for a volume of code that wouldn't be worth the cost, I'd love to hear some reinforcement there as well. Bottom line: If it's not on the iPhone, chances are there's a reason and in this instance, it's because you can't predict the mathematical value of "every third Wednesday" like you can something that's simply every 21 days.
0
Comment
Question by:brucegust
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39956208
What does the number of days in the month have to do with the number of days in a week? Adding 21 days to a starting date isn't going to affect how many Wednesdays fall within that 21-day range. Adding 21 should be fine (for every 3rd Wednesday).

If you were to say that you wanted to schedule meetings the 3rd of every month, THEN you could not simply say "Jan 3rd + 30 days". See the difference?
0
 

Author Comment

by:brucegust
ID: 39956262
Right now, based on the way that I've coded things, if I say I want an even every second Tuesday, I'll schedule it April 8th and hit "submit." When I look at May, the 8th is on a Thursday as opposed to a Tuesday. So I've just frustrated my user because I'm adding 30 days instead of 4 weeks.

I don't have my code in front of me and I put this together a while ago so I'm sorry I can't be more specific with what I've done, but the bottom line seems to be that instead of adding 30 days to a date, I have code available to me that allows me to do something similar to:

Jan 3rd + 4 weeks, rather than Jan 3rd + 30 days..

Correct?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39956302
Are you trying to do this in PHP or Js?

In php you could do something like this

$get_by_dayname = strtotime('2014-03-01 next wednesday');
echo date("d-m-y",$get_by_dayname);
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:brucegust
ID: 39956359
I'm doing this in PHP.

So, if my user wants to schedule an event every third Wednesday, my code needs to be something like:

$everythirdWednesday  = strtotime('$this_Wednesday'+ three weeks);

That puts my event on the third Wednesday of every month. As opposed to this:

$everythreeweeks = strtotime('$this_Wednesday'+21days);

Yes?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39956367
Use the code above to find the first Wednesday then add 14 days or 2 weeks to it
Obviously you need to inject the correct month into the date, March is just an example.
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39956394
Please see this article that answers the instant question and many others.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Every 3rd Wednesday is easily found by adding 21 days to the initial Wednesday.  The 3rd Wednesday of a month is easily found with something like March 1 + 3 Wednesday
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 125 total points
ID: 39956520
...if I say I want an even every second Tuesday, I'll schedule it April 8th and hit "submit." When I look at May, the 8th is on a Thursday as opposed to a Tuesday.
That's because you're mixing up your requirement. Your requirement is not "what day of the week is the 8th of May"; your requirement is "which Tuesday is this (first, second, etc.)".
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 125 total points
ID: 39957124
My example above would break in October this year, so here's a better way

<?php
echo date("d-m-y",strtotime('first wednesday of october 2014 2 weeks'));

Open in new window

Don't think you can get much simpler and easier to understand than that!
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 39957216
You can test your ideas about PHP date/time values on my server here:
http://iconoun.com/demo/strtotime.php
0
 
LVL 58

Expert Comment

by:Gary
ID: 39957243
Ok yours works too and shorter.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question