jedistar
asked on
Calculate Date Help
Hi,
This function calculates 1 year head of dates. How do i make it calculate 1 year before and 1 year after now.
eg: May 2005 - May 2007 in the selection
<?
for ($i = 0; $i < 15; $i++) {
$thisMonth = ($month + $i) % 12;
$thisYear = $year + ($month + $i) / 12;
?>
<option value="<? _e(date("m/Y", mktime(0, 0, 0, $thisMonth, 1, $thisYear))); ?>"><?
_e(date("M Y", mktime(0, 0, 0, $thisMonth, 1, $thisYear))); ?></option>
<?
This function calculates 1 year head of dates. How do i make it calculate 1 year before and 1 year after now.
eg: May 2005 - May 2007 in the selection
<?
for ($i = 0; $i < 15; $i++) {
$thisMonth = ($month + $i) % 12;
$thisYear = $year + ($month + $i) / 12;
?>
<option value="<? _e(date("m/Y", mktime(0, 0, 0, $thisMonth, 1, $thisYear))); ?>"><?
_e(date("M Y", mktime(0, 0, 0, $thisMonth, 1, $thisYear))); ?></option>
<?
ASKER
Ok, currently my date displays as:
<input id="holiday_date" name="holiday_date" type="text" tabindex="2" <?
if (array_key_exists ('holiday_date', $cleanPost))
_e(" value=\"{$cleanPost['holid ay_date']} \"");
else if ($currentQuery)
_e(" value=\"" . $currentQuery->date . "\"");
?>/>
eg: its 2006-01-02 in a texbox format, how do i change it to the format of:
<select id="holiday_day" name="holiday_day" class="f-day" tabindex="4">
<?
for ($i = 1; $i < 32; $i++) {
?>
<option value="<? _e($i); ?>"<?if($i == $day) _e(" selected")?>><? _e($i); ?></option>
<?
}
?>
</select>
<select id="holiday_monthyear" name="holiday_monthyear" class="f-month" tabindex="5">
<?
for ($i = 0; $i < 15; $i++) {
$thisMonth = ($month + $i) % 12;
$thisYear = $year + ($month + $i) / 12;
?>
<option value="<? _e(date("m/Y", mktime(0, 0, 0, $thisMonth, 1, $thisYear))); ?>"><?
_e(date("M Y", mktime(0, 0, 0, $thisMonth, 1, $thisYear))); ?></option>
<?
}
?>
</select>
(points changed to 500)
<input id="holiday_date" name="holiday_date" type="text" tabindex="2" <?
if (array_key_exists ('holiday_date', $cleanPost))
_e(" value=\"{$cleanPost['holid
else if ($currentQuery)
_e(" value=\"" . $currentQuery->date . "\"");
?>/>
eg: its 2006-01-02 in a texbox format, how do i change it to the format of:
<select id="holiday_day" name="holiday_day" class="f-day" tabindex="4">
<?
for ($i = 1; $i < 32; $i++) {
?>
<option value="<? _e($i); ?>"<?if($i == $day) _e(" selected")?>><? _e($i); ?></option>
<?
}
?>
</select>
<select id="holiday_monthyear" name="holiday_monthyear" class="f-month" tabindex="5">
<?
for ($i = 0; $i < 15; $i++) {
$thisMonth = ($month + $i) % 12;
$thisYear = $year + ($month + $i) / 12;
?>
<option value="<? _e(date("m/Y", mktime(0, 0, 0, $thisMonth, 1, $thisYear))); ?>"><?
_e(date("M Y", mktime(0, 0, 0, $thisMonth, 1, $thisYear))); ?></option>
<?
}
?>
</select>
(points changed to 500)
ASKER
you there?
You may want to clarify what you're wanting, I only have a vague idea of what your asking, not nearly enough to try to help.
ASKER
my previous post:
currently my date displays in a textbox, i wish to display it in a form on 2 combobox
day-monthyear -> with the current date selected. the user should be allowed to
select a range of dates +/-1year
currently my date displays in a textbox, i wish to display it in a form on 2 combobox
day-monthyear -> with the current date selected. the user should be allowed to
select a range of dates +/-1year
how about this.
<select name="dates">
<?php
$month = date("m");
$year = date("Y");
for($i = 12; $i > -13; $i--)
{
$date = date("m/Y", mktime(0,0,0, $month-$i, 1, $year));
echo "\t<option value=\"$date\">$date\n";
}
?>
</select>
<select name="dates">
<?php
$month = date("m");
$year = date("Y");
for($i = 12; $i > -13; $i--)
{
$date = date("m/Y", mktime(0,0,0, $month-$i, 1, $year));
echo "\t<option value=\"$date\">$date\n";
}
?>
</select>
ASKER
how do i split up my current date first
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
// get our start time (a year ago), and put
// it in the middle of the month, just to be sure
$date = strtotime('-1 year');
$date = strtotime(date('Y-m-10', $date));
// get our end time (a year from now), and
// put it at the end of the month
$end = strtotime('+1 year');
$end = strtotime(date('Y-m-t', $end));
while ($date <= $end)
{
echo '<option value="'.date('m/Y', $date).'">'.date('M Y', $date).'</option>'."\n";
$date = strtotime('+1 month', $date);
}
?>