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 4578834
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:33:29+00:00 2026-05-21T20:33:29+00:00

i’m working on a website where users can choose various events and add them

  • 0

i’m working on a website where users can choose various events and add them to their timeline. Every event has an opening time and a closing time, they’re saved as ints in the db as of now.
For example an events open at 9 and closes at 18. I need a javascript function to check if the event is open when the user adds it…to make things simple let’s suppose that i alwais check against the actual time.
I’ve got no problems to check in a normal situation (the events start at 9 and closes at 18), i’m finding some problems with events that start at 18 and end at 2 o clock. I’ve divided events in two classes: those where the end date is > than the starting date and those where the end date is < than the starting date, but i don’t know how to check in this second case!

Thx for your help.

EDIT this is the code i used and that worked for me (i was taking the date for checking from html), maybe it helps someone;

        var dataSelezionata = $('#dataSelezionata').html();
        var dataExplode = dataSelezionata.split("/");
        var dataSelezionata = dataExplode[1]+"/"+dataExplode[0]+"/"+dataExplode[2];
        dataSelezionataJavascript = new Date(dataSelezionata);
        var oreAttuali = dataSelezionataJavascript.getHours();
        var oraInizio = parseInt($('#oraInizio').html(), 10);
        var oraFine = parseInt($('#oraFine').html(), 10);
        if (oraInizio && oraFine){
            if (oraFine > oraInizio){
                console.log('ora prima delle 24');
                if (!(oreAttuali >= oraInizio && oreAttuali < oraFine)){
                    alert ("L'evento da lei selezionato non e' disponibile il giorno "+dataSelezionataJavascript.toLocaleDateString()+" alle "+dataSelezionataJavascript.toLocaleTimeString()+"");
                    return;
                }
            }
            if (oraFine < oraInizio){
                console.log('ora fine dopo le 24');
                var tempoApertura = (24 - oraInizio) + oraFine;
                var dataInizio = new Date (dataSelezionataJavascript.getFullYear(), dataSelezionataJavascript.getMonth(), dataSelezionataJavascript.getDay(), oraInizio);
                var dataFine = new Date (dataSelezionataJavascript.getFullYear(), dataSelezionataJavascript.getMonth(), dataSelezionataJavascript.getDay(), oraInizio+tempoApertura);
                if (!(dataSelezionataJavascript >= dataInizio && dataSelezionataJavascript < dataFine)){
                    alert ("L'evento da lei selezionato non e' disponibile il giorno "+dataSelezionataJavascript.toLocaleDateString()+" alle "+dataSelezionataJavascript.toLocaleTimeString()+"");
                    return;
                }
            }
        }
  • 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-05-21T20:33:29+00:00Added an answer on May 21, 2026 at 8:33 pm

    For events that run over midnight (or any event for that matter), just add the duration of the event to the start time, so for an 8 hour event:

    // Set start
    var start = new Date(2011, 4, 3, 18);  // 3 May, 1800
    
    // Set finish for 8 hours later
    var finish = new Date(2011, 4, 3, 18+8); // 4 May, 0200
    

    And do the date comparison as suggested by thomasa88.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters

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.