473,577 Members | 3,319 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date handling

We have some date fields in our HTML forms in various places. In the
accounts package we use, there is some pretty nifty date handling.

It has a standardised date format of dd/mm/yyyy and if you enter e.g.

3-12 it will switch it to 3/12/2005

Same applies for e.g. 3:12 etc

Anyone know of some javascript which will do this for our HTML form
fields? Our target format is actually dd-mon-yyyy and it would make it
really nice for users if the system could accept a variety of input
formats and then switch it to a date to our specification. Any
suggestions?
--

jeremy
Oct 25 '05 #1
8 4081
Jeremy wrote:
We have some date fields in our HTML forms in various places. In the
accounts package we use, there is some pretty nifty date handling.

It has a standardised date format of dd/mm/yyyy and if you enter e.g.

3-12 it will switch it to 3/12/2005

Same applies for e.g. 3:12 etc

Anyone know of some javascript which will do this for our HTML form
fields? Our target format is actually dd-mon-yyyy and it would make it
really nice for users if the system could accept a variety of input
formats and then switch it to a date to our specification. Any
suggestions?


The task is trivial, but first you need to ensure that your users can
not introduce ambiguities.
A sample:
http://www.mickweb.com/demo/datepicker.html
Mick


Oct 25 '05 #2
In article <j6************ *******@twister .nyroc.rr.com>, Mick White
says...
Jeremy wrote:
We have some date fields in our HTML forms in various places. In the
accounts package we use, there is some pretty nifty date handling.

It has a standardised date format of dd/mm/yyyy and if you enter e.g.

3-12 it will switch it to 3/12/2005

Same applies for e.g. 3:12 etc

Anyone know of some javascript which will do this for our HTML form
fields? Our target format is actually dd-mon-yyyy and it would make it
really nice for users if the system could accept a variety of input
formats and then switch it to a date to our specification. Any
suggestions?


The task is trivial, but first you need to ensure that your users can
not introduce ambiguities.
A sample:
http://www.mickweb.com/demo/datepicker.html

Thanks Mick, perhaps I didn't make myself clear. From what I see, you
are enabling the user to select a date from 3 individual fields and then
displaying the resultinto a 4th field

What I am looking to acheive is a single text field in which the user
may type e.g. 3/12/05 and which, as the cursor leaves the field, is
reformatted to 3-dec-2005.

You said it is trivial: is it really?

thanks

--

jeremy

Oct 25 '05 #3
JRS: In article <MP************ ************@ne ws.individual.n et>, dated
Tue, 25 Oct 2005 15:32:24, seen in news:comp.lang. javascript, Jeremy
<je********@gma il.com> posted :
We have some date fields in our HTML forms in various places. In the
accounts package we use, there is some pretty nifty date handling.

It has a standardised date format of dd/mm/yyyy and if you enter e.g.

3-12 it will switch it to 3/12/2005

Same applies for e.g. 3:12 etc

Anyone know of some javascript which will do this for our HTML form
fields? Our target format is actually dd-mon-yyyy and it would make it
really nice for users if the system could accept a variety of input
formats and then switch it to a date to our specification. Any
suggestions?


If you allow an adaptive variety, you need to be reasonably sure that
there are no unexpected cases that are misinterpreted, because your
users may not notice that the switched form is not as expected.

Better IMHO to provide a set of radio-buttons and/or checkboxes to
choose the current format, and to display by onChange or similar the
date of Christmas in the currently selected format.

Do you go as far as allowing 25.XII.2005, 33/11/22, and 2005-W51-7, for
example?

You could try reading the newsgroup FAQ; see below.

--
© 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.
Oct 25 '05 #4
Jeremy wrote:



Thanks Mick, perhaps I didn't make myself clear. From what I see, you
are enabling the user to select a date from 3 individual fields and then
displaying the resultinto a 4th field

What I am looking to acheive is a single text field in which the user
may type e.g. 3/12/05 and which, as the cursor leaves the field, is
reformatted to 3-dec-2005.

You said it is trivial: is it really?


Yes, but you can never be sure what the user will enter.

function convertDate(val ue){
var v=value.split(/[^\d]/);
v[1]=
['jan','feb','ma r','apr','may', 'jun','jul','au g','sep','oct', 'nov','dec'][v[1]-1];
return v.join("-");
}

alert("3/12/05") // "3-dec-2005"
<input ... onchange="this. value=convertDa te(this.value)" >

You're aware that "3/12/2005" is interpreted as "March 12, 2005" in
North America, are you not?
Mick.

Oct 25 '05 #5
Jeremy wrote:
It has a standardised date format of dd/mm/yyyy and if you enter e.g.
3-12 it will switch it to 3/12/2005
Same applies for e.g. 3:12 etc
Anyone know of some javascript which will do this for our HTML form
fields?


Using my generalized date functions at
http://www.javascripttoolbox.com/date/
you could do something like this:

<input type="text" name="date"
onChange="var d=parseDate(thi s.value);if(d== null){alert('Da te format not
recognized!');} else{this.value =formatDate(d,' dd-MMM-yyyy)}">

With the default code, it would automatically recognize and parse dates in
these formats:
y-M-d MMM d, y MMM d,y y-MMM-d d-MMM-y MMM d
M/d/y M-d-y M.d.y MMM-d M/d M-d
d/M/y d-M-y d.M.y d-MMM d/M d-M

You could modify the parseDate function to easily parse more date formats.

You should of course be aware that some values entered will be ambiguous.
1/2/2000 can mean Jan 2, 2000 just as well as Feb 1, 2000, depending on
locale.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Oct 26 '05 #6
In article <tR************ **@merlyn.demon .co.uk>, Dr John Stockton
says...

If you allow an adaptive variety, you need to be reasonably sure that
there are no unexpected cases that are misinterpreted, because your
users may not notice that the switched form is not as expected.
Yes you are quite right. This is however an administrative application
as opposed to something that any member of the public may use and hence
training etc on the behaviour of the system will be available - and they
will know that the target date format is dd-mon-yyyy.
Better IMHO to provide a set of radio-buttons and/or checkboxes to
choose the current format, and to display by onChange or similar the
date of Christmas in the currently selected format.

Do you go as far as allowing 25.XII.2005, 33/11/22, and 2005-W51-7, for
example?

You could try reading the newsgroup FAQ; see below.


Thanks for the pointer.
--

jeremy
Oct 26 '05 #7
In article <YZ************ *******@twister .nyroc.rr.com>, Mick White
says...
You said it is trivial: is it really?

Yes, but you can never be sure what the user will enter.

function convertDate(val ue){
var v=value.split(/[^\d]/);
v[1]=
['jan','feb','ma r','apr','may', 'jun','jul','au g','sep','oct', 'nov','dec'][v[1]-1];
return v.join("-");
}

alert("3/12/05") // "3-dec-2005"
<input ... onchange="this. value=convertDa te(this.value)" >


Thanks, that's very helpful.
You're aware that "3/12/2005" is interpreted as "March 12, 2005" in
North America, are you not?


Noted ta.
--

jeremy
Oct 26 '05 #8
In article <dj*********@ne ws4.newsguy.com >, Matt Kruse says...
Jeremy wrote:
It has a standardised date format of dd/mm/yyyy and if you enter e.g.
3-12 it will switch it to 3/12/2005
Same applies for e.g. 3:12 etc
Anyone know of some javascript which will do this for our HTML form
fields?
Using my generalized date functions at
http://www.javascripttoolbox.com/date/
you could do something like this:

<input type="text" name="date"
onChange="var d=parseDate(thi s.value);if(d== null){alert('Da te format not
recognized!');} else{this.value =formatDate(d,' dd-MMM-yyyy)}">

With the default code, it would automatically recognize and parse dates in
these formats:
y-M-d MMM d, y MMM d,y y-MMM-d d-MMM-y MMM d
M/d/y M-d-y M.d.y MMM-d M/d M-d
d/M/y d-M-y d.M.y d-MMM d/M d-M

You could modify the parseDate function to easily parse more date formats.


OK that looks interesting too.

You should of course be aware that some values entered will be ambiguous.
1/2/2000 can mean Jan 2, 2000 just as well as Feb 1, 2000, depending on
locale.


Thanks for the reminder.
--

jeremy

Oct 26 '05 #9

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

Similar topics

3
1527
by: Sune | last post by:
I'm working on a system that requires alot of date handling, and i'm getting pretty tired of doing custom calculating when modifying dates, so i hope someone would be able to help me. Is there any easy way to do re-calculating of dates? such as adding 2,11 or 36 months to a date, and have it automatically checking whether or not it should...
2
6947
by: Tatiana Zadiraka | last post by:
I use DB2 8.1 with FixPack 5. In command line for sql I get all DATE columns only in MM-DD-YYYY format. Of course, DATE('20-12-2003') gives me an error SQL0181N The string representation of a datetime value is out of range. SQLSTATE=22007 My db config is: Database territory = RU
1
2595
by: DKode | last post by:
I find myself writing repetitive functions for handling null values from my DB like so: Private Function SetDateNull(ByVal p_date As Object) As Date If (TypeOf (p_date) Is System.DBNull) Then p_date = Date.MinValue End If Return p_date End Function
3
1384
by: Dr John Stockton | last post by:
For an all-numeric Gregorian date to be intrinsically unambiguous, it must generally be of the form /\d{3,}\D+\d+\D+\d+/ ; and we've discussed handling that. But if the month is given in letters (in full, as a LTA, or as Roman numerals) , then the date is unambiguous if the value of the year field is greater than the greatest possible...
1
3022
by: JonathanParker | last post by:
Another quick one! Trying to search for records by both accounting period and by year in two seperate queries actioned by option buttons. I've sorted the formatting so it's in a UK format but I keep getting the same error '(3122) you tried to execute a query that does not include the specific expression 'tblAccounting.Period=0406 And...
2
11496
by: syntego | last post by:
We commonly use triggers to log changes to our main tables to historical log tables. In the trigger, we create a concatenated string of the old values by casting them as follows: CAST(O.MYDATE AS CHAR(30)) When directly updating date fields in the main table, the logged value gets saved in the format YYYY-MM-DD as expected.
3
1620
by: bhavu10 | last post by:
hi i have created a form forreport with today, week month & year CMD Button but i think i wrote the code wrong for month and also it shows me only records for this year whewe as i have 2006 records too code is written in Event Procedure of Respective Cmd Button Can there be a problem in TODAY'S Cmd Button code that it shows me only 2007...
7
3003
by: bruce.dodds | last post by:
Access seems to be handling a date string conversion inconsistently in an append query. The query converts a YYYYMM string into a date, using the following function: CDate(Right(,2) & "/1/" & Left(,4)) I entered the string "200715" in a record to test an error condition.
10
3269
by: ashore | last post by:
Guys, the line below just returned "Dec 07" as the date for one month back from today. Hardly life-threatening, but any thoughts? <?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));?> AS
0
7846
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...
0
7777
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8123
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. ...
0
8289
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6519
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...
0
5341
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...
1
2292
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
1
1388
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1111
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...

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.