473,382 Members | 1,766 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,382 software developers and data experts.

make a date pretty

I'd like a Javascript snippet that converts a dot.net style date
string (say, 9/1/2006) into the pretty version (September 1st, 2006),
so my users get a visual cue when they are entering January 2nd,2009
when they meant to enter Febuary 1st, 2009. Does anyone have such a
thing lying around somewhere? I'm not much of a javascript programmer.
Oct 2 '08 #1
7 1432
qu**********@gmail.com wrote:
I'd like a Javascript snippet that converts a dot.net style date
string (say, 9/1/2006) into the pretty version (September 1st, 2006),
so my users get a visual cue when they are entering January 2nd,2009
when they meant to enter Febuary 1st, 2009. Does anyone have such a
thing lying around somewhere?
Yes, it's in the archives. Using Google Groups already, you will have no
difficulty at all to find them.
I'm not much of a javascript programmer.
That's tough luck, though.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Oct 2 '08 #2
On Oct 3, 7:37*am, quillbrea...@gmail.com wrote:
I'd like a Javascript snippet that converts a dot.net style date
string (say, *9/1/2006) into the pretty version (September 1st, 2006),
so my users get a visual cue when they are entering January 2nd,2009
when they meant to enter Febuary 1st, 2009. *Does anyone have such a
thing lying around somewhere? *I'm not much of a javascript programmer.
If you don't know much about javascript, you wont know good code from
bad so spend a bit of time learning the basics. You can probably find
hundreds of scripts and libraries that will do what you want, but
writing it yourself isn't that tough.

Below is an example - not production ready but should start you on the
right track:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Enter Date</title>
<style type="text/css">
body {
font-family: geneva, arial, sans-serif;
}
td {
vertical-align: top;
}
#dateA_full {
font-family: arial, sans-serif;
font-size: 80%;
color: #666666;
background-color: ffffff;
}

</style>
<script type="text/javascript">

// Expects date, month, year
function validateDate(d, m, y) {
var D = new Date( y + '/' + m + '/' + d);
return d == D.getDate() && m == (D.getMonth()+1);
}

// Adds 'st', 'nd', etc. to numbers
function addOrdinal(n) {
n = n % 100;
var s = ["th", "st", "nd", "rd", "th"];
var ord = (n<21)? ((n < 4)? s[n] : s[0])
: ((n%10 4)? s[0] : s[n%10]);
return n + ord;
}

// Expects a date as dd/mm/yyy, returns as date with ordinal
// month as word and year, e.g.
// 1/2/2008 -1st February, 2008
function formatDate(txt) {
var months = ['','January', 'February', 'March', 'April',
'May', 'June', 'July', 'August', 'September',
'October', 'November', 'December'];
var dateBits = txt.split('/');

if (dateBits.length == 3 &&
validateDate(dateBits[0], dateBits[1], dateBits[2]))
{
return addOrdinal(dateBits[0]) + ' ' +
months[dateBits[1]] + ', ' +
dateBits[2];
} else {
return 'Doesn\'t seem to be a valid date&hellip;';
}
}

</script>
</head>
<body>
<table>
<tr>
<td>Enter date (dd/mm/yyyy):
<td><input type="text" name="dateA" onblur="
document.getElementById('dateA_full').innerHTML =
formatDate(this.value);
">
<br>
<span id="dateA_full">&nbsp;</span>
</table>

</body>
</html>
--
Rob
Oct 3 '08 #3
In comp.lang.javascript message <7cdd2227-7218-483b-a89d-13da62683a02@x4
1g2000hsb.googlegroups.com>, Thu, 2 Oct 2008 19:11:59, RobG
<rg***@iinet.net.auposted:
return d == D.getDate() && m == (D.getMonth()+1);
var dateBits = txt.split('/');
If a RegExp match is used instead of Array split, and if that match
allows at most two digits for day-of-month, then only the Month equality
test will be needed.

Your code fails in Century Zero (no sense of history in the ex-
Colonies?) <g>.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Oct 3 '08 #4
On Oct 3, 7:33*pm, dhtml <dhtmlkitc...@gmail.comwrote:
* 2.10 Internationalization and Multinationalization in javascript.

| *For example, there is an International Standard
| for numeric Gregorian date format; but none for decimal
| and thousands separators.

There is a separator defined in CLDR. If you want to L10N on the client,
for dates, currencies, numbers, look into CLDR. I can't at the moment
bring up unicode.org site, but it is there.

The same thing goes for dates.
Whatever CLDR means, it is not an International Standard unless it has
been published by ISO as such.

To get an International Standard for decimal and thousands separators,
it would at present be necessary for the French and the Americans to
agree on which of them should change. IMHO, that will not happen,
until enforced by the Chinese.

--
(c) John Stockton, near London, UK. Posting with Google.
Mail: J.R.""""""""@physics.org or (better) via Home Page at
Web: <URL:http://www.merlyn.demon.co.uk/>
FAQish topics, acronyms, links, etc.; Date, Delphi, JavaScript, ....|
Oct 5 '08 #5
Dr J R Stockton wrote:
On Oct 3, 7:33 pm, dhtml <dhtmlkitc...@gmail.comwrote:
> 2.10 Internationalization and Multinationalization in javascript.

| For example, there is an International Standard
| for numeric Gregorian date format; but none for decimal
| and thousands separators.

There is a separator defined in CLDR. If you want to L10N on the client,
for dates, currencies, numbers, look into CLDR. I can't at the moment
bring up unicode.org site, but it is there.

The same thing goes for dates.

Whatever CLDR means, it is not an International Standard unless it has
been published by ISO as such.
The Unicode Common Locale Data Repository. It's not a standard for
thousands separators (an impossibility at present, as you observe
below), but, as the name indicates, is planned to be a good place, when
it is released, to obtain the correct value.
To get an International Standard for decimal and thousands separators,
it would at present be necessary for the French and the Americans to
agree on which of them should change. IMHO, that will not happen,
until enforced by the Chinese.
--
John W. Kennedy
"Give up vows and dogmas, and fixed things, and you may grow like
That. ...you may come to think a blow bad, because it hurts, and not
because it humiliates. You may come to think murder wrong, because it
is violent, and not because it is unjust."
-- G. K. Chesterton. "The Ball and the Cross"
Oct 6 '08 #6
On Oct 4, 5:31*am, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
In comp.lang.javascript message <7cdd2227-7218-483b-a89d-13da62683a02@x4
1g2000hsb.googlegroups.com>, Thu, 2 Oct 2008 19:11:59, RobG
<rg...@iinet.net.auposted:
* * *return d == D.getDate() && m == (D.getMonth()+1);
* * *var dateBits = txt.split('/');

If a RegExp match is used instead of Array split, and if that match
allows at most two digits for day-of-month, then only the Month equality
test will be needed.
Sure, but I don't think it provides any benefit. The RegExp can be
build once to save some processing power, but you are still trading a
RegExp comparison with a getMonth comparison. Calling it several
thousand times in succession may prove the point but I think it's
moot.

Your code fails in Century Zero (no sense of history in the ex-
Colonies?) <g>.
Some of us claim to have been here for 60,000 years or so - I'm not
sure the Gregorian calendar has much meaning for that timeframe, "the
dreaming" seems far more appropriate. ;-)
--
Rob
Oct 6 '08 #7
John W Kennedy wrote:
Dr J R Stockton wrote:
>On Oct 3, 7:33 pm, dhtml <dhtmlkitc...@gmail.comwrote:
>> 2.10 Internationalization and Multinationalization in javascript.

| For example, there is an International Standard
| for numeric Gregorian date format; but none for decimal
| and thousands separators.

There is a separator defined in CLDR. If you want to L10N on the client,
for dates, currencies, numbers, look into CLDR. I can't at the moment
bring up unicode.org site, but it is there.

The same thing goes for dates.

Whatever CLDR means, it is not an International Standard unless it has
been published by ISO as such.

The Unicode Common Locale Data Repository. It's not a standard for
thousands separators (an impossibility at present, as you observe
below), but, as the name indicates, is planned to be a good place, when
it is released, to obtain the correct value.
I'm not that versed in unicode standards -- far from being an expert,
but here's what I have read and what I understand from it:-

Grouping separator is apparently localized. Not a "standardized" symbol.
It varies between locales.

| For example, the decimal separator set could include all of [.,']

http://unicode.org/reports/tr35/tr35...ormat_Patterns
| G.1 Number Patterns
|
| The NumberElements resource affects how these patterns are interpreted
| in a localized context. Here are some examples, based on the French
| locale. The "." shows where the decimal point should go. The "," shows
| where the thousands separator should go. A "0" indicates zero-padding:
| if the number is too short, a zero (in the locale's numeric set) will
| go there. A "#" indicates no padding: if the number is too short,
| nothing goes there. A "¤" shows where the currency sign will go. The
| following illustrates the effects of different patterns for the French
| locale, with the number "1234.567". Notice how the pattern characters
| ',' and '.' are replaced by the characters appropriate for the locale.

The last two lines state that the "pattern characters" are "replaced by
the characters appropriate for the locale."

>To get an International Standard for decimal and thousands separators,
it would at present be necessary for the French and the Americans to
agree on which of them should change. IMHO, that will not happen,
until enforced by the Chinese.
I think the point is that the separator varies, but that variance is
taken on by CLDR.

Garrett
Oct 6 '08 #8

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

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
4
by: Joe User | last post by:
Hi all....I have a feeling this is going to be one of those twisted query questions, but here it goes anyways.... I want to generate a report that shows the chronology of events (represented by...
4
by: Oreo Bomb | last post by:
I have a secured database that contains a Read-Only group. This group has permissions to view reports, but cannot add, edit, or delete any DB objects. One of the reports the group needs access to...
8
by: Michael A. Covington | last post by:
Is there a way to make a C# program print the date on which it was compiled? Finding the file date of the executable is one way, but it's not foolproof. Thanks!
12
jaccess
by: jaccess | last post by:
Hello all, I am trying to create a running total based on a specific date range that is to be entered into a form. I currently have the form set up with 2 text boxes (date1 and date2) which are...
3
by: salad | last post by:
I have an A97 application that is NOT split on a network. It is used by 15+ folks continually. It is quick and fast. I split it several years ago and had to merge it together again after the...
12
by: Atropo | last post by:
Hi all. Having several strings how do i combine them to construct a command; lets say to run the date command. string str = "14/10/08 19:06:09"; strDD = str.substr(0,2); strMM =...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
1
by: joshai | last post by:
Hi, I'm pretty new to the php/mysql world and am building an article database for a website with multiple content types. I have an entry screen built that allows the site owner to enter articles,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.