I have a textbox on one of my forms that is used to accept a time from the
user. I need to write this value to a database to trigger an event later on.
What I'd like to know is...
Are there any functions in javascript that can convert different time
formats to a known format (24 hour clock)... 5pm -> 17:00 or 5:00 to 05:00,
etc. ???
Assuming that I get the input into a 24 hour format, how can I create a full
time/date variable with todays date and the users entered time?
Finally, if the entered time is earlier than the current time, how can I
create the above date/time combination using tomorrows date?
Thanks!!! 2 2498
Noozer wrote: I have a textbox on one of my forms that is used to accept a time from the user. I need to write this value to a database to trigger an event later on.
What I'd like to know is...
Are there any functions in javascript that can convert different time formats to a known format (24 hour clock)... 5pm -> 17:00 or 5:00 to 05:00, etc. ???
You need to parse whatever is input and feed it to your own date
functions, probably all you need to know is here:
<URL:http://www.merlyn.demo n.co.uk/js-dates.htm> Assuming that I get the input into a 24 hour format, how can I create a full time/date variable with todays date and the users entered time?
A date object representing what the user's machine thinks is the
current local time can be created with:
var now = new Date();
Adjusting the the time is shown below in a short example:
<input type="text" name="aTime" onblur="
var theTime = new Date();
var t = this.value.spli t(':');
theTime.setHour s( t[0] );
theTime.setMinu tes( t[1] );
theTime.setSeco nds( 0 );
alert( theTime );
var now = new Date();
if ( now > theTime ) {
theTime.setDate ( theTime.getDate () + 1 );
}
alert ( theTime );
"> Finally, if the entered time is earlier than the current time, how can I create the above date/time combination using tomorrows date?
Yes, see above. But there are three big caveats:
1. You must validate whatever the user enters to ensure it is
something your functions will like, which means checking they entered
properly formatted numbers and that they are within an acceptable
range. For example, if you enter say 37:102 to the above example, it
will quite happily interpret it as 14:42 tomorrow.
2. The clock on the users machine may be wrong, so that 'now' is not
today, or it may be sufficiently inaccurate as to cause spurious
results for certain times.
3. The user may not have javascript enabled/available.
Over to you!
--
Rob
JRS: In article <w9lHe.80648$5V 4.77990@pd7tw3n o>, dated Mon, 1 Aug 2005
08:35:40, seen in news:comp.lang. javascript, Noozer <do*******@me.h ere>
posted : Are there any functions in javascript that can convert different time formats to a known format (24 hour clock)... 5pm -> 17:00 or 5:00 to 05:00, etc. ???
Yes.
Assuming that I get the input into a 24 hour format, how can I create a full time/date variable with todays date and the users entered time?
with (D = new Date()) setHours(H, M, S)
or with (D = new Date()) setUTCHours(H, M, S)
where H M S are numbers or strings for hours minutes seconds.
N.B. VERY ancient browsers may not allow multiple parameters in
setHours().
Finally, if the entered time is earlier than the current time, how can I create the above date/time combination using tomorrows date?
Add
if (D < new Date()) D.setDate(D.get Date()+1)
or if (D < new Date()) D.setUTCDate(D. getUTCDate()+1)
If there is any possibility of the actual time, or of H M S, being
affected to Summer Time clock changes in Spring and Autumn, then test
carefully that what happens is satisfactory.
If efficiency matters, which is unlikely, do parameterless new Date()
only once. That's also vital if the user may be working at local (or
UTC) midnight.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David Messner |
last post by:
Ok I know this is simple but the statement eludes me...
I have a date field where I want the default value on the data entry form's
date field to be the last date entered. I figure I can do this with a query
but don't know what the criteria needs to be.
Any help would be appreciated,
Thanks
|
by: Jimi Ffondu |
last post by:
Hi there - it's pretty simple, and I'm an idiot. I'm not a developer,
I just seem to have landed in this job building this Access database -
I've got two days to make it work... aaahh!
1) Within the User Interface, I've got a separate section for the
administrator to modify the data in the tables, via a series of
add/remove/edit forms. I'd like to control the opening of the
maintenance menu (on click of a button on the main front...
|
by: Neo Geshel |
last post by:
This works:
<form>
<asp:TextBox id="name" />
<%= name.ClientID %>
</form>
But this DOES NOT work:
<form>
|
by: ricky.agrawal |
last post by:
I'm really not sure how to go about this in Access. What I've created
is a table for each location. Those tables are identical in format but
different in information.
The tables are named after key points such as the store number and the
store ID. The fields of those tables are generic fields such as sales
per day, bank deposit and what not. The first field for each store
table is the date and I've set that as the primary key as one...
|
by: Timothy.Rybak |
last post by:
Hello all,
This is my first attempt at an application, so kid gloves are
appreciated.
I need to make a very simple form that only has a few elements. One is
TraceCode - a text field that is populated when a user scans a label.
The other is ScanDate - a date/time field that should equal the
date/time of the scan (e.g. 7/31/2006 5:00:00 AM).
| |
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I get the value of a form control?
-----------------------------------------------------------------------
In HTML documents, named forms may be referred to as named
properties of the « document.forms » collection, and named form
controls may be referred to as named properties of the form's
elements collection:
var frm = document.forms;
|
by: newbie |
last post by:
i have a form in which a hidden field (initial value as '0', and my
javascript set it to '1' when an event is trigged).
In the same form, i have a reset field. But I realized that the hidden
field is not reset to '0' when i push the
reset button. If I simply change the node from
"<input type="hidden" id='IsChanged' value='0'>"
to
"<input type="text" id='IsChanged' value='0'>"
Everything is working as expected (the value is reset to '0'...
|
by: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= |
last post by:
Hi,
I have been using the code (some of it has been removed for simplicity)
below to allow authenticated (using ASP.NET membership database) users to get
a file from their archive area. It seems to work fine, however I noticed
that no web log entry is added when a successful download occurs (normally a
200 HTTP status code, however, if there is an authorization failure, it gets
logged). I have a logging routine that logs a successful...
|
by: phill86 |
last post by:
Hi,
I am trying to represent on a form time slots I have re-created the look of an outlook calendar on the form I have a table with the calendar bookings start and end time and there could be any number of bookings in a day. The following code represents the column for the first day of the week (monday) and formats the text boxes accordingly if the room is booked.
This all works fine but I have to have this code again to represent the...
|
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...
|
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...
| |
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...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |