-1

Hi I am working on a project where client wants to update a variable at 12:00 PM

Technologies:

  1. CodeIgniter 3
  2. Bootstrap 4 js
  3. JQuery UI Any help will be appreciated!
Muhammad Ahmod
  • 649
  • 4
  • 15
  • Stack Overflow is not a code writing service. If you want someone to help you, research the problem, write code and then come back here to show what code you have written and where you are stuck. – David van Driessche Aug 31 '20 at 21:22
  • but if you don't know where to start then where can I go? Muhammad Ahmod gave me answer and helped me you also could I have written a simpe datepicker code. If you say so I can send it to you. – Muhammad Usman Sep 01 '20 at 04:46
  • That's what's called research, @Muchammad Usman. There are plenty of resources on the Internet that discuss similar things. – David van Driessche Sep 01 '20 at 05:47
  • Yes there are but I didn't found any starting where to start and what to do. So I started by asking here. – Muhammad Usman Sep 02 '20 at 12:25

2 Answers2

0

here is a basic guide of how this can be done...

// Set the next delivery date
var NextDelivery = null;

function CalcTimeOut(){
   var cutOffTime = new Date();
   var currentTime = new Date();
   var difference = null;

   if(cutOffTime.getHours() < 12) {
      // If we are before 12 we can deliver today
       cutOffTime.setHours(12,0,0,0);
      NextDelivery = new Date();
   } else {
      // Set new cutoff time
      cutOffTime.setHours(36,0,0,0);
      // If we are after 12 we can only deliver tomorrow.
      var currentDate = new Date();
      currentDate.setDate(currentDate.getDate() + 1);
      currentDate.setHours(0,0,0,0);
      NextDelivery = currentDate;
   }
   var difference = (cutOffTime.getTime() - currentTime.getTime());
   // Recalculate if we need to...
   setTimeout(function(){
      CalcTimeOut();
   }, difference);
}

// Call from where ever you need to.
CalcTimeOut();
Muhammad Ahmod
  • 649
  • 4
  • 15
0

I looked at the code of Huhammad Ahmod and It really helped me to fix the issue. by the way here is the fix of the problem I derived. index.html

    <!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
    <script src="app.js"></script>
    <title>Document</title>
</head>
<body>
<input type="date" id="date">
</body>
</html>

and in app.js I did the following things:

$(document).ready(function (){
// Set the next delivery date
   var NextDelivery = null;

   $('#date').change(function (){
   // // CalcTimeOut();
   // //    today();
   //    difference();
      Updated();
});
function Updated(){
      var current=new Date();
      var selected=document.getElementById('date').value;
      var selectedDate=new Date(selected);
      var uDate;
      if (selectedDate.getDate()==current.getDate() && selectedDate.getMonth()==current.getMonth()){

          if (current.getHours()<12){

              uDate=current.getDate();
         }
         else{
            uDate=current.getDate()+1;
         }
      }
      else{
         uDate=selectedDate.getDate();
      }
      var uMonth;
      if (selectedDate.getMonth()+1<10){
         var next=selectedDate.getMonth()+1;
         uMonth='0'+next;
      }
      else {

            uMonth = selectedDate.getMonth() + 1;
      }
      if (uDate<10){
         uDate='0'+uDate;
      }
      var orderDate = selectedDate.getFullYear()+'-'+uMonth+'-'+uDate;
      console.log(orderDate);
      document.getElementById('date').value=orderDate;
}

});

Less then 10 was used to fix the format issue of YYYY-MM-DD error given by input type="Date"