Need help with IF statement script trigered by date

Discussion in 'HTML & Website Design' started by Ahmed_AA, Mar 14, 2007.

  1. #1
    I am creating site about Islam and muslims (www.islammuslim.lv) and I want that on site would be daily praying times. They changes day from day so I need unique for every day. On internet there is some 2-3 muslim portals who offers javascript code and they send to your site prayer times, but they do not give enough options for making it fit in design.

    So I am trying to create my self script in which I could wrote in those prayertimes.

    As far as I understand I need something like this:

    var now date = 14/03/2007
    var now date = 15/03/2007
    var now date = 16/03/2007
    var now date = 17/03/2007
    etc

    so if (or case) today = 14/03/2007 then display 04:33 06:43 12:33 15:34 18:24 20:24
    so if (or case) today = 15/03/2007 then display 04:32 06:41 12:32 15:36 18:26 20:26
    so if (or case) today = 16/03/2007 then display 04:30 06:40 12:32 15:38 18:28 20:28
    so if (or case) today = 17/03/2007 then display 04:29 06:38 12:31 15:39 18:29 20:29

    etc

    So how does it is in Javascript code?
     
    Ahmed_AA, Mar 14, 2007 IP
  2. DeLaVega

    DeLaVega Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Please let me know if I understood correctly:

    
    
    
    <script language="JavaScript">
    var date = new Date();
    var today = date.getFullYear() + '/' + date.getMonth() + '/' + date.getDate();
    
    switch (today)
    {
    case '2007/2/15':
    	document.write('04:33 06:43 12:33 15:34 18:24 20:24');
    
    case '2007/2/16':
    	document.write('04:33 06:43 12:33 15:34 18:24 20:24');
    
    default:
    
    }
    
    </script>
    
    
    HTML:
     
    DeLaVega, Mar 15, 2007 IP
  3. Ahmed_AA

    Ahmed_AA Guest

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks. It is almost what I need. Almost, becouse it do not work properly.
    It creates both results so I get displayed:

    04:33 06:43 12:33 15:34 18:24 20:2404:33 06:43 12:33 15:34 18:24 20:24

    What could be problem?
     
    Ahmed_AA, Mar 15, 2007 IP
  4. Ahmed_AA

    Ahmed_AA Guest

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Tried to edit and find the problem by "merging" with another similar script, but this do not work at all:

    <script language="JavaScript">
    var nowdate = new Date();
    var currDate = nowDate.getFullYear() + '/' + nowDate.getMonth() + '/' + nowDate.getDate();
    switch (true)
    {
    case (currDate = '2007/2/15'):
        document.write('04:33 06:43 12:33 15:34 18:24 20:24');
    case (currDate = '2007/2/16'):
        document.write('04:33 06:43 12:33 15:34 18:24 20:24');
    default:
    }
    </script>
    Code (markup):
     
    Ahmed_AA, Mar 15, 2007 IP
  5. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #5
    Better to use php + mysql for the whole year .
     
    commandos, Mar 15, 2007 IP
  6. rgchris

    rgchris Peon

    Messages:
    187
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I don't really know how prayer times shift from day to day, but isn't there at least some sort of formula for it? The way you have it now you're going to either have to a) constantly update it or b) have a huge list of days. Just seems like a problem.

    Also, I've noticed with the code is that the dates are wrong. They're set to fire if it's February, not March. And you might want to put something in the default case.
     
    rgchris, Mar 15, 2007 IP
  7. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #7
    what country are those number for ahmad ?


    rgchris no there is no formula , it depend on the sun (when it come on , when it come off , at noon , etc ...)
     
    commandos, Mar 15, 2007 IP
  8. crenok

    crenok Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8

    The break; statement is missing. Try this one:

    <script language="JavaScript">
    var date = new Date();
    var today = date.getFullYear() + '/' + date.getMonth() + '/' + date.getDate();
    
    switch (today)
    {
    case '2007/2/15':
        document.write('04:33 06:43 12:33 15:34 18:24 20:24');
        break;
    
    case '2007/2/16':
        document.write('04:33 06:43 12:33 15:34 18:24 20:24');
        break;
    
    default:
    
    }
    
    </script>
    Code (markup):
     
    crenok, Mar 15, 2007 IP
  9. Ahmed_AA

    Ahmed_AA Guest

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    There is some kind of astranomic calculation for longitutes and latitudes.
    I do not have such programm. Also there is difirence of opinion about Fajr (some time before sunrise. When first light is apearing) and Isha (early night, when sky loses its sunset redding). Those difirences of opinion is minimal, more important on which metodology is made calculation for far north and south areas for times when day is very long (not talking about polar days). Some say that You can take Iša right after Sunset prayer, some says 2 (or 1,5) houers, some calculates on partition between sunset and sunrise. So there is some difirences - but that is not so important, becouse I can just choose one. But still, that calculatin as I understand is not an option.

    More easy is to write in those numbers from calculation results.
    If I would put that script for some 2 months, it will not be such problem I think.

    As I understand that 0 is for january, 1 is for february and 2 is for march, so I think he is correct. But I will check.


    commandos:
    I`m from Latvia, ethnic latvian.

    Better to use php + mysql for the whole year .
    ----------
    I do not like php. To complicated. My knowledge about scripting is very small, I just opened Frontpage only when I started to build my website.
     
    Ahmed_AA, Mar 15, 2007 IP
  10. DeLaVega

    DeLaVega Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    opps :rolleyes:

    I missed the break statement! Sorry :)

    Thanks Crenok! :)

    (Firefox JavaScript debugger did not warn me :( )
     
    DeLaVega, Mar 15, 2007 IP
  11. Ahmed_AA

    Ahmed_AA Guest

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Yes, it is working.

    I noticed that there was no break and I add but this way (and it didnt work):
    case '2007/2/15':
        document.write('04:33 06:43 12:33 15:34 18:24 20:24');
        break;
    case '2007/2/16':
        document.write('04:33 06:43 12:33 15:34 18:24 20:24');
        break;
    default:
    Code (markup):
    I did not know that there must be empty space between them. Thanks. Thanks DeLaVega, ofcourse too. I spent truly many days and houers for trying to solve my prayingtime script problem.
     
    Ahmed_AA, Mar 15, 2007 IP
  12. DeLaVega

    DeLaVega Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    You're welcome :)

    I think there's no need to have empty lines between them, it just a matter of make the code clearer and more readable :)

    It should work the same with or without them :)
     
    DeLaVega, Mar 15, 2007 IP
  13. rgchris

    rgchris Peon

    Messages:
    187
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Weird, I had no idea Javascript worked on a 0-11 system for months.
     
    rgchris, Mar 15, 2007 IP