473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Form entry to Time part of database Date entry?

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!!!
Aug 1 '05 #1
2 2489
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.demon.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.split(':');
theTime.setHours( t[0] );
theTime.setMinutes( t[1] );
theTime.setSeconds( 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
Aug 1 '05 #2
JRS: In article <w9lHe.80648$5V4.77990@pd7tw3no>, dated Mon, 1 Aug 2005
08:35:40, seen in news:comp.lang.javascript, Noozer <do*******@me.here>
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.getDate()+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.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 1 '05 #3

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

Similar topics

11
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...
2
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) ...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
13
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...
17
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...
17
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get the value of a form control? -----------------------------------------------------------------------...
11
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...
7
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...
4
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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
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,...

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.