Limiting the current date in javascript according to specific hours and minutes

Prevent users from selecting the current date if the current time exceeds a specified hour using JavaScript.

This is what I have attempted:

var d = new Date();
var restricttime = '<?php echo $restrictTime->time_restriction ?>';
var restrictmin = '<?php echo $restrictTime->restrict_min ?>';

var hour = d.getHours();
var minutes_hr = d.getMinutes();

if (restricttime >= hour) {
    if (minutes_hr > restrictmin && restricttime >= hour) {
        min_Date = 0;
    } else {
        min_Date = 1;
    }
} else {
    min_Date = 0;
}

$("#datepicker-13").datepicker({
    minDate: min_Date
});

I believe there might be an issue with the logic in this code. Can someone please assist me?

Answer №1

One option is to utilize the relative date properties. It's worth experimenting with this approach.

    if(minutes_hr > restrictmin && restricttime >= hour){
          min_Date= "-1d";
    }else{ 
          min_Date= new Date();
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The navigation/hamburger icon vanishes after a click on a page link

I'm in the process of creating a single-page scrolling website. However, I am encountering an issue with the navigation bar. Specifically, when I click on a page link from the nav bar at screen widths less than 780px (when the hamburger icon appears), ...

Failure in SystemJS during ahead-of-time compilation due to missing NgZone provider

Previously, I have successfully used Angular's ahead-of-time compilation. However, after adding routing and lazy loading to my app, I am facing difficulties in making it work again. Upon updating my code to the latest 2.0 release, it functions well w ...

Collaborating with Ladda button functionality

I have a button with ladda functionality, shown below. <button class="btn btn-primary btn-xs ladda-button" data-style="slide-left" data-size="xs" v-on:click="refreshPage()">Refresh</button> The onClick event is triggered by VueJs. When the b ...

Utilizing Codeigniter for transmitting JSON data to a script file

When querying the database in my model, I use the following function: function graphRate($userid, $courseid){ $query = $this->db->get('tblGraph'); return $query->result(); } The data retrieved by my model is then encoded in ...

Building a favorite feature in Django using HTML

Currently, I am working on implementing an Add to Favorite feature. So far, I have succeeded in displaying a button with an icon based on the value of the is_favorite field, but I am facing difficulties updating my database. I would like to know: How can ...

Do not reveal result of coin flip using Javascript and API

Even though I meticulously copied my professor's parsing process, the display isn't turning out as expected. It seems like something is off in my code. <div class="main"> <p>Heads or tails? click to toss the coin</p> & ...

Angular-jasmine: conducting tests on a component that utilizes timeout to render the DOM

Within my custom directive, I have implemented the following functionality: link: function (scope, element) { var editor = CKEDITOR.inline(element.find('div[contenteditable]')[0], {} To ensure that the directive is properly linked and that ...

Next.js is causing an error by not recognizing the document variable

While diving into the world of next.js, I encountered an interesting challenge. In my project, I came across this puzzling error. The culprit seemed to be a module called Typed.js, which threw me off with a peculiar message: Server Error ReferenceError: d ...

Slider-activated Pie Chart Controller

I have successfully created a pie chart using highchart and javascript, allowing me to adjust each slice individually using a slider. However, I am facing an issue where I want the maximum value of the pie to be 100%, with the other sliders contributing to ...

Finding out which carousel the user is currently engaging with in the Slick Carousel can be accomplished by following these steps

I am struggling with applying a class to the carousel container when the first slide is active in a page that contains multiple Slick carousels. Is there a way to update the code below so that the class is only applied to the specific carousel the user is ...

Issue with Mongoose $in operator causing updates to only affect a single document

Having some issues with the "$in" operator in Mongoose. I have a User schema that includes an array of Card schema. The Card schema contains a 'score' field that I want to update based on a list of Card ids. Here's what I have attempted: Us ...

Having trouble loading HTML content from another file

Here is the code snippet in question: <script> var load = function load_home(){ document.getElementById("content").innerHTML='<object type="type/html" data="/linker/templates/button.html" ></object>'; } </script> ...

When attempting to access the id-data, an error is thrown indicating that the property 'username' of null cannot be read

Is there a way to transfer a user's data to their profile? I have successfully retrieved the complete user information from the API and displayed it on the user's page. However, I encounter an error when attempting to display the same data on the ...

AngularJS: Implementing a toggle click function for a list of items within an iframe

Here's the workflow I'm dealing with: I have a collection of items, each having an ng-click event that triggers the display of an iframe below the clicked item. The process works like this: When clicking an item, a hidden div tag beneath it ap ...

Tips for enhancing the appearance of a React component

I have a redux form that doesn't look great, and I would like to style it. However, my project uses modular CSS loaders. The styling currently looks like this: import styled from 'styled-components'; const Input = styled.input` color: #4 ...

Exploring Angular controllers, promises, and testing

Currently, I am in the process of writing some unit tests for my controller that utilizes promises. The code snippet in question is as follows: UserService.getUser($routeParams.contactId).then(function (data) { $scope.$apply(function () { $sco ...

Encountering a Laravel Nova issue where attempting to override a Vue component leads to a Vue warning: Error

Recently, I decided to incorporate a user guide into my nova using the following Vue Shepherd library. To make this work, I made some adjustments in the files within the nova directory. One of these changes involved renaming the file "webpack.mix.js.dist" ...

Is it possible to dynamically call a component in Vue.js using a variable name

Can a Vue.js component be called by using a variable name? The components are registered like this: import Component1 from 'component1' import Component2 from 'component2' import Component3 from 'component3' ... components: ...

Rename multiple files in bulk

With 10000 files consisting of php, html, css, and png formats that are interconnected to operate the website's engine, I am looking for a way to perform bulk renaming in order to ensure proper functionality. Not only do I need to rename the actual fi ...

Please select the option to choose all values

Currently, I am working on implementing a select option feature on my webpage. I have integrated PHP into it to ensure that the selected option remains unchanged after submission. My goal is to include a value of "any" so that when the user chooses "ANY," ...