I added the code for generating the due dates for present day.

Can you Please help me how can i generate the vaccination due date by selecting the date of birth.

Here is my code in

app/design/frontend/ultimo/default/template/vaccination/vaccination.phtml

 <?php
    $nextWeek = time() + (7 * 24 * 60 * 60);
               // 7 days; 24 hours; 60 mins; 60 secs
    echo 'Now:       '. date('d-m-Y') ."\n";
    //echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
    // or using strtotime():
    echo 'Three Week: '. date('d-m-Y', strtotime('+3 week')) ."\n";
    echo 'Six Week: '. date('d-m-y', strtotime('+6 week')) ."\n";
   ?>

This is the date of birth in

app/design/frontend/ultimo/default/template/child/child.phtml

 <form action="http://www.labwise.in/devel/vaccination-details/" method="post" id="form-validate"> <li> <label class="required"for="birthday"><em>*</em><?php echo $this->__('Date Of Birth')?></label> <div class="input-box dob"> <select name="month" class="input-text required-entry validate-select" style="width: 100px;"onchange="call()" > <option value="">Month</option> <option value="1">January</option> <option value="2">Febuary</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="day" class="form-error" style="width: 100px;" id="day"> <option value="">Day</option> </select> <select name="year" class="form-error" style="width: 100px;" id="year" > <option value="">Year</option> </select> </div> </li>

***<div class="button"> <p class="required"><?php echo $this->__('* Required Fields') ?></p> <button id= "dueDateCalSubmit" type="Submit" class="button"    title="<?php echo $this->__('Generate') ?>" name="send" id="send2"><span><span><?php echo $this->__('Generate') ?></span></span></button> </div>***

<script type="text/javascript"> 

 function call()
{ 
var kcyear = document.getElementsByName("year")[0], 
kcmonth = document.getElementsByName("month")[0], 
kcday = document.getElementsByName("day")[0]; 
var d = new Date(); 
var n = d.getFullYear(); 
for (var i = n; i >= 2000; i--) 
{ 
    var opt = new Option(); 
    opt.value = opt.text = i;
    kcyear.add(opt);
} 



 kcmonth.addEventListener("change", validate_date); 

function validate_date() 
{
 var y = +kcyear.value, 
 m = kcmonth.value,
 d = kcday.value; 
 if (m === "2") 
    var mlength = 28 + (!(y & 3) && ((y % 100) !== 0 || !(y & 15))); 
 else 
     var mlength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][m - 1];
    kcday.length = 0; 
 for (var i = 1; i <= mlength; i++) 
    { 
        var opt = new Option(); 
        opt.value = opt.text = i; 
        if (i == d) opt.selected = true; 
        kcday.add(opt); 
    } 
} 
validate_date();
} 
 </script> 
Member Avatar for diafol

I haven't considered this code closely, but why aren't you using a datepicker?

So your vet is open 7 days a week?

Don't add seconds in order to change the date, use the DateTime object and add with a DateInterval.

What's going on with all that javascript? A datepicker will give you a calendar.

can you please add datepicker in my code.I tried but it has not worked.

Member Avatar for diafol

A datepicker should give you a valid date, whereas separate dropdowns need to be passed to a validator as you can end up with something like 2014-09-31, which is obviously invalid or the issue with leap years.

So the choice is between validation convenience and user convenience (datepickers may be more awkward than dropdowns - especially for mobile users).

Your PHP code though could be modernized:

$dates = [];
$dt = new DateTime(); //now
$dates['one_week'] = $dt->add(new DateInterval('P1W'))->format('Y-m-d');
$dates['three_week'] = $dt->add(new DateInterval('P2W'))->format('Y-m-d');
$dates['six_week'] = $dt->add(new DateInterval('P3W'))->format('Y-m-d');

echo "<pre>";
print_r($dates);
echo "</pre>";

or even:

$dt = new DateTime(); //now
$dates = [$dt->add(new DateInterval('P1W'))->format('Y-m-d'), $dt->add(new DateInterval('P2W'))->format('Y-m-d'), $dt->add(new DateInterval('P3W'))->format('Y-m-d')];

echo "<pre>";
print_r($dates);
echo "</pre>";

Coming back to the datepicker - you can choose a bog-standard HTML5 datepicker (may not display correctly across all browseers - check first) or select a script of your choice, e.g. jQueryUI. There are literally hundreds of these out there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.