473,473 Members | 2,215 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

If statement script for date based var

4 New Member
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:
if:
var today = 14/03/2007
var today = 15/03/2007
var today = 16/03/2007
var today = 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 it should be in Javascript code?
Mar 14 '07 #1
6 1224
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN.

How many dates are you going to have? Is it for the whole year?

You should read up on the Date object and the Array object.
Mar 14 '07 #2
AhmedAA
4 New Member
Welcome to TSDN.

How many dates are you going to have? Is it for the whole year?

You should read up on the Date object and the Array object.
Yes it is for whole year, but maybe I will put script for some 2 months and later change to next 2 months for keeping script smaller in size.

I read those links, but understood little.

Should I use this as trigger for my case?

Expand|Select|Wrap|Line Numbers
  1. var myDate=new Date()
  2. myDate.setFullYear(2007,3,14)
  3. myDate.setFullYear(2007,3,15)
  4. myDate.setFullYear(2007,3,16)
  5. myDate.setFullYear(2007,3,16)
???
Please, could You write it for me, if it is not comlicated.

As far as I understand, then I need script in which if today is like 15. march, then output is: 04:32 06:41 12:32 15:36 18:26 20:26
If today is 16.march then output is: 04:30 06:40 12:32 15:38 18:28 20:28

And so I would edit it for all year...
Mar 14 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
There are a number of ways you could do this. Obviously, there are more complicated ways which are a lot neater, but to keep it simple, just declare an array, with your values, e.g.
Expand|Select|Wrap|Line Numbers
  1. var prayingTimes = new Array();
  2. prayingTimes["15032007"]="04:32 06:41 12:32 15:36 18:26 20:26 ";
and likewise for all other dates.

Then to access a particular date, just call:
Expand|Select|Wrap|Line Numbers
  1. var today = new Date();
which will give today's date. Then convert it to a string value and access the array:
Expand|Select|Wrap|Line Numbers
  1. document.write(prayingTimes[dateStr]);
Mar 15 '07 #4
AhmedAA
4 New Member
Sorry, but I know so little that I can not make what You adviced. I tried to undeerstand by reading links, but it is too much for me.


But on another forum one man gave to me this script and it is working:

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2. var date = new Date();
  3. var today = date.getFullYear() + '/' + date.getMonth() + '/' + date.getDate();
  4.  
  5. switch (today)
  6. {
  7. case '2007/2/15':
  8.     document.write('04:33 06:43 12:33 15:34 18:24 20:24');
  9.     break;
  10.  
  11. case '2007/2/16':
  12.     document.write('04:33 06:43 12:33 15:34 18:24 20:24');
  13.     break;
  14.  
  15. default:
  16.  
  17. }
  18.  
  19. </script>
Sorry for not using Your efferts.
Mar 15 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
That's ok, no problem. There are many alternatives. Thanks for posting your working solution.

Just one thing though, to avoid confusion, I think you should add one to the month. The "2" is actually March, so try:
Expand|Select|Wrap|Line Numbers
  1. var today = date.getFullYear() + '/' + (date.getMonth()+1) + '/' + date.getDate();
and then in your switch cases, you can put the 'real' date.

Of course, it will still work as it is, but this will make it easier if you debug later.
Mar 16 '07 #6
AhmedAA
4 New Member
Well, I now that 0-11, so I will better keep it simple as it is. Some modification can create a confussion. Bet may be I will later think otherwise.

Thanks.
Mar 20 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Mike A | last post by:
Hi, I'm hoping someone can help me with this. I have a URL for which I'd like to limit access to by time. For example,say I have a URL that I don't want accessable on Monday mornings between...
3
by: Mark Morton | last post by:
I'm writing an if statement for a UK credit card form validation script. Users who specify that their card is Switch need to enter either the issue number or the 'valid from' date. I'm trying to...
5
by: Steve | last post by:
Hello, I've been a PHP programmer for a number of years and have just started to learn JS. My Employer (a water analysis lab) wants what should be a very simple .js written that basically takes...
3
by: Johnny M | last post by:
using Access 2003 Pardon the subject line, but I don't have a better word for this strange behavior (or behavior I don't understand!!!) I have a class module named DepreciationFactor. One of...
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
19
by: rdavis7408 | last post by:
Hello, I have four textboxes that the user enters the price per gallon paid at the pump, the mileage per gallon and I would like to then calculate the cost per gallon and use a switch statement to...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
2
by: jonathan184 | last post by:
Hi I am trying to create a shell script that will look for a contracthead file first and if the contract head file does not exist on day1 exit script. Now on day2 if contracthead exists or...
1
by: somnamblst | last post by:
I have a Flash form that uses ASP to write to Access db. I have an HTML form that uses ASP to upload files and email those files and sends copies to recipients based on the form fields. I would like...
8
by: John | last post by:
Hi, gurus, How can I implement the following feature in C#: Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group") For Each objMember In objGroup.Members...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.