always-a-learner always-a-learner - 8 days ago 4
jQuery Question

get date from float number in php or jquery

I am working on a project in which i have to Generate a Date from Selected Option value.

Example:


  1. If selected
    1.5
    then need a date after 1 Month 15 days
    15-08-2017

  2. If selected
    1.0
    then need a date after 1 Month
    17-08-2017


    <select class="form-control" name="days" id="days" required>
    <option data-days="1.5" value="3">After 1 month 15 days</option>
    <option data-days="2.5" value="4">After 2 month 15 days</option>
    <option data-days="6.0" value="10">After 5 month</option>
    <option data-days="7.5" value="30">After 7 month 15 days</option>
    //And So on...
    </select>

    // Here is the script for getting selected option days attribute.
    $('body').on('change', '#days', function(e) {
    var days = $(this).find(':selected').data('days');

    // Now How do i get the date according the days. as shown in example

    });



I have also tried to get the date in
PHP
but i didn't get it.

$date = date('Y-m-d', strtotime('+1.0 month'));


So can anyone help me to get date using this
float
numbers in
PHP
or
Jquery
.

Answer
$final = date("Y-m-d", strtotime("+1 month", $time));

you can use this. for 1 month

or

for adding 1 day

$final = date("Y-m-d", strtotime("+1 day", $time));

for adding more than one day $final_date = date("Y-m-d", strtotime("+15 day", strtotime($date)));

$float_number = '4.5'; 

$nubers = explode('.', $float_number); 

$date = date('Y-m-d', strtotime('+'.$nubers[0].' month')); 

if($nubers[1] == '0'){ 

$final_date = $date; 

} else { 

$final_date = date("Y-m-d", strtotime("+15 day", strtotime($date))); 

} 

print_r("Final Date: ".$final_date);