1

I am a beginner at javascript, and I'm looking just for a way to generate a specific day of the week, without any conditions, which I want to practice myself. I'm going through some confusion while reading the documentation. Basically, what I want to tell the javascript is to display a tag at a certain day of the week, at a certain time of the day.

For instance, display on Monday between 19:00-21:00.

I have this and I don't really know how to change whatever is in the element. I feel like I'm not going anywhere with this.

<script type="text/javascript">
element = document.getElementById('broadcast-live')
var datestart = new Date("December 28, 2012 17:00:00")
var date_end = new Date("December 28, 2012 22:00:00")

function DisplayLiveBroadcast()
{
    if (new Date => datestart)
    {
        document.write("<div id=\"broadcast-live\">Live on air (Started Friday, 21:00)<div/>")
    }
    else if (new Date => date_end)
    {
        document.write("<div id=\"broadcast-live\"> <div/>")
    }
    else
    {
            document.write("<div id=\"broadcast-live\"> <div/>")
        }
    }
</script>
zzwyb89
  • 472
  • 1
  • 7
  • 21
  • 3
    Do you have any code you've tried already that we could see? – gotohales Dec 28 '12 at 16:32
  • 1
    What exactly are you having problems with? To find out which weekday it is for a given day? – Felix Kling Dec 28 '12 at 16:34
  • I've only tried a function and an if statement, but this is as far as I got, I'm tiny confused with the Date() function. – zzwyb89 Dec 28 '12 at 16:35
  • @zzwyb89 hint. `Date()` isn't terribly useful. Use it as a constructor: `new Date()` – John Dvorak Dec 28 '12 at 16:36
  • There are 2 questions there. First, how to find out if you're in a specific range. Second, how to get the data from a Google Docs spreadsheet. For the first question, remember that Javascript is on the client. Which means that Monday 19:00-21:00 is not the same for me and the people in different timezones. For the second question, you'd better ask another question. – Florian Margaine Dec 28 '12 at 16:36
  • I'm attempting to display the
    tag with text inside it only on the specified date and time in the code.
    – zzwyb89 Dec 28 '12 at 16:37
  • possible duplicate of [How to get the day from a particular date using JavaScript](http://stackoverflow.com/questions/495644/how-to-get-the-day-from-a-particular-date-using-javascript) – Felix Kling Dec 28 '12 at 16:46
  • I've added the code I've written to the first post, I'm not sure if it would work. It is not exactly what I wanted, but it will do for now. – zzwyb89 Dec 28 '12 at 17:29

1 Answers1

2

Try this out, which uses a getDay() method that returns an integer value referring to the current day: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/getDay

Simon Sarris
  • 62,212
  • 13
  • 141
  • 171
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • 1
    http://w3fools.com/ why not point to [MDN](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/getDay) isntead – mplungjan Dec 28 '12 at 16:38
  • 3
    It's saddening to see high rep people linking to w3schools. – Florian Margaine Dec 28 '12 at 16:39
  • I had a look at this, thank you, but I believe it's returning the current day we have? The thing I want to achieve, is for JS to check what day it is, and using an if statement (I guess?) display the div tag, else leave it as it is e.g
    – zzwyb89 Dec 28 '12 at 16:41
  • I've added the code I've written to the first post, I'm not sure if it would work. It is not exactly what I wanted, but it will do for now. – zzwyb89 Dec 28 '12 at 16:59