# Create a 3,6,9 and 12 monthly schedule

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Hello,

In MYSQL would like to produce a field for 3,6,9 or 12 months just
containing the dates of every 7 days from the current date.  I think I
need a mixture of PHP and MYSQL to achieve this.

Looked all over and can't find a sausage.

Darren

## Re: Create a 3,6,9 and 12 monthly schedule

I noticed that Message-ID:
contained the following:

Check out mktime()

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

## Re: Create a 3,6,9 and 12 monthly schedule

bigfella wrote:

\$months = 3; // or 6, or 9, or 12
\$now = time();
\$day = \$now + 7*24*60*60;
\$cutoff = strtotime("+\$months months");
while (\$day <= \$cutoff) {
\$date = date('Y-m-d', \$day);
\$insert = "INSERT INTO the_table SET date='\$date'";
mysql_query(\$insert);
\$day = \$day + 7*24*60*60;
}

Cheers,
NC

## Re: Create a 3,6,9 and 12 monthly schedule

Thank-you so much NC,

could this be changed to produce a straight 31 days?

Darren

## Re: Create a 3,6,9 and 12 monthly schedule

bigfella wrote:

Of course:

\$cutoff = strtotime('+31 days');
\$now = time();
\$day = \$now + 24*60*60;
while (\$day <= \$cutoff) {
\$date = date('Y-m-d', \$day);
\$insert = "INSERT INTO the_table SET date='\$date'";
mysql_query(\$insert);
\$day = \$day + 24*60*60;
}

Read up on strtotime(), it's really powerful:

http://www.php.net/strtotime

Cheers,
NC