473,765 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

time intervals

Can anyone tell me how to write a routine that uses time-intervals, I would
like to dynamically create an array of times like this:

9:00
9:30
10:00
10:30

This has an interval of half an hour, but I want to be flexible for future
use, so a variable called interval should be set to define the intervals.

Jul 20 '05 #1
1 2898
JRS: In article <tO************ *********@amsne ws02.chello.com >, seen in
news:comp.lang. javascript, Marco Alting <ma***@alting-multimedia.nl>
posted at Tue, 19 Aug 2003 17:06:33 :-
Can anyone tell me how to write a routine that uses time-intervals, I would
like to dynamically create an array of times like this:

9:00
9:30
10:00
10:30

This has an interval of half an hour, but I want to be flexible for future
use, so a variable called interval should be set to define the intervals.

See reference in FAQ, and below.

Assuming that you do not need times between 23:59 and when-the-clocks-
go-back, you can use D = new Date("1/1/1 9:30") or with (D = new
Date()) setHours(9,30,0 ,0) or D = new Date(36000000-1800000) or
D = new Date(0,0,1,9,30 ,0) to initialise D ;
D.setMinutes(D. getMinutes()+30 ) to increment it; and pick out the
result with X = D.toGMTString() .match(/\d+:\d\d/).

OTOH, you could do it as you would with pencil and paper. Start with
HH=9 and MM=30, then
MM += interval ; HH += Math.floor(MM/60) ; MM %= 60

Incrementing by fractional minutes should now be obvious.

D.setTime(D.get Time()+1800000) // alternative.

Then assign the resulting strings to successive array elements,
remembering to add some way of stopping.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5219
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much appreciated. TIA
2
47856
by: Shaun | last post by:
Hi, I have a table called Bookings which has two important columns; Booking_Start_Time and Booking_End_Time. These columns are both of type DATETIME. Given any day how can I calculate how many hours are available between the hours of 09.00 and 17.30 so a user can see at a glance how many hours they have unbooked on a particular day (i.e. 8.5 hours less the time of any bookings on that day), can this be done with a query or do I have to...
3
2700
by: Dave | last post by:
Hi I am hoping someone might be able to help me out with this. I am writing a helpdesk system which records agents logging in and out of the system. I need to write a stored procedure which will show the peak number of agents logged in concurrently during a specified time period. Within the time period, the person viewing the report should be able to
6
18670
by: Penguin | last post by:
At some long ago time Steve Jorgensen answered thus: Subject: Re: How can I round a time? Newsgroups: comp.databases.ms-access Date: 1998/12/11 Access represents a date internally as a double and will convert between date/time and double automatically. The double value Access (or VB) creates is based on 1 day = 1.0 and the fractional part represents a
2
4344
by: Rombolt | last post by:
Hi I have a MSSQL table with many time intervals stored as datetime. Each time interval is also assigned a numeric type that specifies what type of job was done during the time interval. I need to add-up the time intervals by type, make sure overlaping portions of intervals are not accounted for twice and also respect interval type priorities. Here's a theoric example: Priority is given to types 30, 50 and 70. Meaning that when there's an...
9
8299
by: Ron Adam | last post by:
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the following to try to determine which. import time # Determine if time.time is better than time.clock # The one with better resolution should be lower.
1
1779
by: lenygold via DBMonster.com | last post by:
I found this query on older thread and i can not uderstand output interval pairs: How to find min and max values in date intervals: -------------------------------------------------- Input: CREATE TABLE INTERVALS (key CHAR(5) NOT NULL ,level CHAR(7) NOT NULL ,date_from DATE NOT NULL
9
3311
by: Ross | last post by:
I'm a newbie at this, and have searched a lot but can't find something that seems appropriate for measuring a recurring elapsed time. Creating an object with: var mydate = new Date(); seems clear, as is creating a second: nowTime = new Date(); and getting a difference between the two. My quesiton is what if you have many, maybe thousands of intervals you wish to measure? Should I do: nowTime = new Date(); with every pass of a...
15
6438
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but but that only gave me difference in hours and only if the times were on the same day (after wrapping with date() function). TIA
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2805
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.