Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 10:19 AM
Kevin Lin
Guest
 
Posts: n/a
Default Date/time calculation

Hi,

I'm trying to come up with a function using PHP/MySQL (preferably a PHP only
solution) to find the next time that matches a particular pattern, where the
pattern is a combination of values or wildcards for minute, hour, day,
weekday, month (like a predictive version of Unix's cron.)

So, for example, I might ask for the next time that will match 8:00AM on a
Monday, the next time that will match 15 minutes past midnight on the 1st of
the month, or the next time it will be 11:59 on a Friday the 13th.

It is quite easy to figure out whether or not a particular time matches
these criteria, but I can see no way to predict when the next time it will
happen.

Any suggestions?

- Kevin


  #2  
Old July 17th, 2005, 10:19 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: Date/time calculation

Kevin Lin wrote:[color=blue]
> I'm trying to come up with a function using PHP/MySQL (preferably a PHP only
> solution) to find the next time that matches a particular pattern, where the
> pattern is a combination of values or wildcards for minute, hour, day,
> weekday, month (like a predictive version of Unix's cron.)
>
> So, for example, I might ask for the next time that will match 8:00AM on a
> Monday, the next time that will match 15 minutes past midnight on the 1st of
> the month, or the next time it will be 11:59 on a Friday the 13th.
>
> It is quite easy to figure out whether or not a particular time matches
> these criteria, but I can see no way to predict when the next time it will
> happen.
>
> Any suggestions?[/color]

Check if today matches the criteria;
if it doesn't, check tomorrow;
if tomorrow doesn't match, check the next day;
.... ... ... ...


Yes, I know it's slow (next Thursday Christmas is due in 1520 days!)


<?php
$match = time();
while(true) {
if (day_month_week_check($match)) break;
/* ^^^^^^^^^^^^^^^^^^^^ TODO */
$match += 24*60*60;
}
/* now deal with hours and minutes :) */
?>
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles