-1

this is my code in ejs file :

<select class="form-control track-change input-lg" data-track="deadline" name="Deadline" id="Deadline" placeholder="Deadline">
    <option value="0" class="task-option project-option default-option" selected="selected" style="display: block;">No deadline</option>
    <option value="12" class="task-option" >12 Hours</option>
    <option value="24" class="task-option project-option" style="display: block;">24 Hours</option>
    <option value="48" class="task-option">2 Days</option>
    <option value="72" class="task-option project-option" style="display: block;">3 Days</option>
    <option value="168" class="task-option project-option" style="display: block;">1 Week</option>
    <option value="336" class="project-option" style="display: none;">2 Weeks</option>
    <option value="504" class="project-option" style="display: none;">3 Weeks</option>
    <option value="731" class="project-option" style="display: none;">1 Month</option>
</select>

When a user chooses 12 Hours I need to save the date now +12 Hours in MySQL, and if choose 2 Days I need to save the date now + 2 Day from now, etc.

How can I do it using nodejs or ejs (jade) or javascript? I need just Date code not sql query ...any help please?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • Where is the code you've tried? – Jonathan Hall Feb 04 '17 at 10:46
  • when u see the value for example in 12 Hours the value is 12 when i save it in mysql its return a 30-11-2001 ..so i dot try anything so far ...any idea? – Fares Alkhwaja Feb 04 '17 at 10:48
  • Incrementing any date part is pretty much the same, see [*Add +1 to current date*](http://stackoverflow.com/questions/9989382/add-1-to-current-date/9989458#9989458). – RobG Feb 04 '17 at 10:53

1 Answers1

0

Assuming that you can call a function every time you select the option, you can do this

function deadlineChanged(hours){
   let newTime = new Date(new Date().getTime() + (hours * 60 * 60 * 1000));
   ///do whatever you want to do with the new time
}

if you want to convert it to mysql string, you can use this function

function formatdate(date) {
if (date instanceof Date) {
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var year = date.getFullYear();
    return year + "-" + (month >= 10 ? month : "0" + month) + "-" + (day >= 10 ? day : '0' + day);
} else {
    return date;
}
}
kkesley
  • 3,258
  • 1
  • 28
  • 55