Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8928629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:29:12+00:00 2026-06-15T08:29:12+00:00

I have a select dropdown with times in 30 min intervals like 11:00 AM,

  • 0

I have a select dropdown with times in 30 min intervals like

11:00 AM, 11:30 AM, 12:00 PM, 12:30 PM, 1:00 PM

beginning from 0:00 AM and ending with 11:30 PM

<select id='time'>
  <option value="11:30 AM">11:30 AM</option>
  <option value="12:00 PM">12:00 PM</option>
  <option value="12:30 PM">12:30 PM</option>
  <option value="1:00 PM">1:00 PM</option>
 <option value="1:30 PM">1:30 PM</option>
 <option value="2:00 PM">2:00 PM</option>
 <option value="2:30 PM">2:30 PM</option>
 <option value="3:00 PM">3:00 PM</option>
 <option value="3:30 PM">3:30 PM</option>
 <option value="4:00 PM">4:00 PM</option>
 <option value="4:30 PM">4:30 PM</option>
</select>

$(document).ready(function(){

  $('#time').val(.now()); // this wouldnt work it gives the current time which may be between 30 min 

});

I want this select dropdown to default to rounded to nearest higher time based on current time.

For eg. if the current time is 10:46 AM then the selected value should 11:00 AM and if the current time is 10:31 AM should also default to 11:00 AM.

Any pointers on achieving this using jquery or with normal javascript.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:29:13+00:00Added an answer on June 15, 2026 at 8:29 am

    You could use the Math.round function to get the value to the nearest half hour:

    Math.round(Date.now()/(30*60*1000))*(30*60*1000));
    

    Construct a date object from this and get the time.

    var date = new Date(Math.round(Date.now() / (30 * 60 * 1000)) * (30 * 60 * 1000));
    $('#time').val(date.getHours()%12 + ":" + ("0"+date.getMinutes()).slice(-2) + " " + (date.getHours() >= 12 ? "PM" : "AM"));
    

    Here is a demonstration: http://jsfiddle.net/GsR6v/9/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a time dropdown that shows hour in one select, minutes in another
Suppose I have a dropdown (select tag) with 3 values. Our first option has
I have an issue regarding to auto populating a select dropdown from jQuery/JSON data
I have a dropdown outside the iframe <select id=ModuleDropDown> <option>Hello world</option> </select> and I
I have a little dropdown menu similar <select> , which contolled from external js-function.
I have a PHP script for a select dropdown box to display times in
I have a select (dropdown) in a form. When I change the value in
I have a value stored in Google App Engine datastore, selected from a dropdown
I have jNiceIT plugin for Jquery. How can i disable the select dropdown styled
I'm using JQgrid, with a select/dropdown in my project, and have implemented it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.