473,320 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,320 software developers and data experts.

Need of a code snipet which converts mm/dd/yy to dd/mm/yy

Hi ,
I am stuck with a requirement from my client to change the date
format from mm/dd/yy to dd/mm/yy .If any body can help me out with
this regard as its very much urgent.


Regards,
Santanu
Jun 27 '08 #1
19 1866
On 22 Apr, 11:02, santanu mishra <mishra.sant...@gmail.comwrote:
Hi ,
I am stuck with a requirement from my client to change the date
format from mm/dd/yy to dd/mm/yy .If any body can help me out with
this regard as its very much urgent.

Regards,
Santanu
I use:
http://www.koders.com/javascript/fid...4E48720E2.aspx
Jun 27 '08 #2
santanu mishra meinte:
Hi ,
I am stuck with a requirement from my client to change the date
format from mm/dd/yy to dd/mm/yy .If any body can help me out with
this regard as its very much urgent.
Untested:

function convert(dateString) {
var new = dateString.split("/");
return new[1]+"/"+new[0]+"/"+new[2];
}

Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Jun 27 '08 #3
Gregor Kofler wrote:
santanu mishra meinte:
> I am stuck with a requirement from my client to change the date
format from mm/dd/yy to dd/mm/yy .If any body can help me out with
this regard as its very much urgent.

Untested:
function convert(dateString) {
var new = dateString.split("/");
return new[1]+"/"+new[0]+"/"+new[2];
}
If that doesn't work, try replacing the variable name new with a
different name. I wouldn't be surprised if that's a problem.
Jun 27 '08 #4
Stevo meinte:
Gregor Kofler wrote:
>santanu mishra meinte:
>> I am stuck with a requirement from my client to change the date
format from mm/dd/yy to dd/mm/yy .If any body can help me out with
this regard as its very much urgent.

Untested:
function convert(dateString) {
var new = dateString.split("/");
return new[1]+"/"+new[0]+"/"+new[2];
}

If that doesn't work, try replacing the variable name new with a
different name. I wouldn't be surprised if that's a problem.
Yes, my mistake. Something like "newDateString" is definitely better,
than a reserved word.

Gregor

--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Jun 27 '08 #5
Gregor Kofler wrote on 22 apr 2008 in comp.lang.javascript:
Stevo meinte:
>Gregor Kofler wrote:
>>santanu mishra meinte:
I am stuck with a requirement from my client to change the date
format from mm/dd/yy to dd/mm/yy .If any body can help me out with
this regard as its very much urgent.

Untested:
function convert(dateString) {
var new = dateString.split("/");
return new[1]+"/"+new[0]+"/"+new[2];
}

If that doesn't work, try replacing the variable name new with a
different name. I wouldn't be surprised if that's a problem.

Yes, my mistake. Something like "newDateString" is definitely better,
than a reserved word.
function convert(d) {
return (d = d.split('/'))[1]+'/'+d[0]+'/'+d[2];
};

or

function convert(d) {
return d.replace(/(\d\d\/)(\d\d\/)/,'$2$1');
};

both tested IE7.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #6
Evertjan. wrote:
Gregor Kofler wrote on 22 apr 2008 in comp.lang.javascript:
>Stevo meinte:
>>Gregor Kofler wrote:
santanu mishra meinte:
I am stuck with a requirement from my client to change the date
format from mm/dd/yy to dd/mm/yy .If any body can help me out with
this regard as its very much urgent.
Untested:
function convert(dateString) {
var new = dateString.split("/");
return new[1]+"/"+new[0]+"/"+new[2];
}
If that doesn't work, try replacing the variable name new with a
different name. I wouldn't be surprised if that's a problem.
Yes, my mistake. Something like "newDateString" is definitely better,
than a reserved word.

function convert(d) {
return (d = d.split('/'))[1]+'/'+d[0]+'/'+d[2];
};

or

function convert(d) {
return d.replace(/(\d\d\/)(\d\d\/)/,'$2$1');
};

both tested IE7.
I'd stick with what Gregor created. It's simple, efficient and easy to
understand by whoever gets to maintain the code in the future.
Jun 27 '08 #7
Stevo wrote on 22 apr 2008 in comp.lang.javascript:
>function convert(d) {
return (d = d.split('/'))[1]+'/'+d[0]+'/'+d[2];
};

or

function convert(d) {
return d.replace(/(\d\d\/)(\d\d\/)/,'$2$1');
};

both tested IE7.

I'd stick with what Gregor created. It's simple, efficient and easy to
understand by whoever gets to maintain the code in the future.
As you wish, Stevo. Why is it efficient?

The above is simple javascript.
I wouldn't recomment having my code maintained
by someone that does not understand the above.

And like all good functions, it can be seen as a black box from outside.

You could feel the need to add all kinds of validation for bad input,
however.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #8
Evertjan. wrote:
Stevo wrote on 22 apr 2008 in comp.lang.javascript:
>>function convert(d) {
return (d = d.split('/'))[1]+'/'+d[0]+'/'+d[2];
};
or
function convert(d) {
return d.replace(/(\d\d\/)(\d\d\/)/,'$2$1');
};
both tested IE7.
I'd stick with what Gregor created. It's simple, efficient and easy to
understand by whoever gets to maintain the code in the future.
As you wish, Stevo. Why is it efficient?
I just mean that it's simple, efficient ENOUGH, and immediately obvious
(without more than 2 seconds of thought) what it's doing. If you know
what the split method does, then you know what the function is doing.
The above is simple javascript.
I wouldn't recomment having my code maintained
by someone that does not understand the above.
We see almost every day people coming here that are given the task by
their employers of changing some code that they don't understand. We
might think that's a dumb idea, but it's happening all the time.

I'm not a fan of regexp constructs because of their lack of readability
to those unfamiliar with them, and that is a large proportion of
programmers that just never get into them. I don't mind admitting that I
fall into that group too. So the only reason I know what your second
function is doing, is because I know what job it has to do from the OP's
original requirements. If I didn't have that knowledge, then I'd be
wondering what this $2$1 business is all about. I've deduced that what
you've got in parentheses is looking for digit, digit, forward-slash and
when it finds one it generates the $1 token, then it looks again for
digit, digit forward slash and generates the $2 token, then the replace
happens and $2 and $1 get swapped in the returned string. If I didn't
have those OP requirements, I can guarantee I'd be at wikipedia's
regular expression page trying to find out what's going on. Don't get me
wrong, I'm impressed with it, but I'd never use it.
Jun 27 '08 #9
Evertjan. meinte:
function convert(d) {
return (d = d.split('/'))[1]+'/'+d[0]+'/'+d[2];
};

or

function convert(d) {
return d.replace(/(\d\d\/)(\d\d\/)/,'$2$1');
};

both tested IE7.
Agreed. But optimization should be the last step. Besides, I suppose the
OP might have problems with understanding the condensed code or the reg
ex (which might be slower than the split).

Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Jun 27 '08 #10
In article <fu*************@news.t-online.com>, Stevo <no@mail.invalid>
wrote:
Evertjan. wrote:
Stevo wrote on 22 apr 2008 in comp.lang.javascript:
>function convert(d) {
return (d = d.split('/'))[1]+'/'+d[0]+'/'+d[2];
};
or
function convert(d) {
return d.replace(/(\d\d\/)(\d\d\/)/,'$2$1');
};
both tested IE7.
I'd stick with what Gregor created. It's simple, efficient and easy to
understand by whoever gets to maintain the code in the future.
As you wish, Stevo. Why is it efficient?

I just mean that it's simple, efficient ENOUGH, and immediately obvious
(without more than 2 seconds of thought) what it's doing. If you know
what the split method does, then you know what the function is doing.
The above is simple javascript.
I wouldn't recomment having my code maintained
by someone that does not understand the above.

We see almost every day people coming here that are given the task by
their employers of changing some code that they don't understand. We
might think that's a dumb idea, but it's happening all the time.

I'm not a fan of regexp constructs because of their lack of readability
to those unfamiliar with them, and that is a large proportion of
programmers that just never get into them. I don't mind admitting that I
fall into that group too. So the only reason I know what your second
function is doing, is because I know what job it has to do from the OP's
original requirements. If I didn't have that knowledge, then I'd be
wondering what this $2$1 business is all about. I've deduced that what
you've got in parentheses is looking for digit, digit, forward-slash and
when it finds one it generates the $1 token, then it looks again for
digit, digit forward slash and generates the $2 token, then the replace
happens and $2 and $1 get swapped in the returned string. If I didn't
have those OP requirements, I can guarantee I'd be at wikipedia's
regular expression page trying to find out what's going on. Don't get me
wrong, I'm impressed with it, but I'd never use it.
I agree 100% with this. I almost never use regexp for just this reason,
because they are unreadable. This doesn't stop me writing large apps
which are efficient enough.
Jun 27 '08 #11
In comp.lang.javascript message <4da1f25e-7bd2-4a20-91ce-9b49d37394dd@v2
3g2000pro.googlegroups.com>, Tue, 22 Apr 2008 04:02:39, santanu mishra
<mi************@gmail.composted:
>Hi ,
I am stuck with a requirement from my client to change the date
format from mm/dd/yy to dd/mm/yy .If any body can help me out with
this regard as its very much urgent.
St = "mm/dd/yy"
St1 = St.substring(3,6) + St.substring(0,3) + St.substring(6)
St2 = St.substr(3,3) + St.substr(0,3) + St.substr(6)
St3 = St.replace(/(..).(..)/, "$2/$1")
x = [St1, St2, St3].join(" ") // to show results

Note that it will also convert "dd/mm/yy" to "mm/dd/yy"; thus it can be
sold in the USA.

Those who decline to learn simple RegExp use are wasting their own
future time, unless they decide to give up programming in favour of a
less intellectual pursuit, such as politics.

An OP who needs to ask such a question should do likewise.

Aside : is there a representation, known to browsers, for the old-style
s as in "Ye olde faufage-fhop" in which I used f instead?

--
(c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm: about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
Jun 27 '08 #12
On Wed, 23 Apr 2008 19:27:55 +0200, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:
Aside : is there a representation, known to browsers, for the old-style
s as in "Ye olde faufage-fhop" in which I used f instead?
&#x17F; or ſ
--
Rik Wasmus
Jun 27 '08 #13
Dr J R Stockton wrote:
Those who decline to learn simple RegExp use are wasting their own
future time, unless they decide to give up programming in favour of a
less intellectual pursuit, such as politics.

An OP who needs to ask such a question should do likewise.
Is there any need for that?

There are a lot of us that don't consider RegExp a good alternative.

Imagine how much code is being run in the background to parse a RegExp
string. In this particular example, the code that Gregor provided, which
was a simple array split, followed by a simple concatenation, was (a)
extremely easy to understand, and (2) doesn't involve very complex
regexp parsing in the background. The code that handles the split and
concatenation code behind the scenes we can all imagine is fairly
trivial. The same can't be said for a RegExp parser.

I prefer two lines of code that are easy to understand and as far as
complexity goes, what you see is pretty much all that's happening. The
RegExp version is not obvious if you're unfamiliar, and involves too big
an overhead in the background. Certainly too big for this particular
case. If you're parsing a humongous length string then the RegExp
overhead would pay off because the code you'd have to write wouldn't be
just two lines.

I have used RegExp code before, I always fully comment what it does
though, and if the alternative (as in this case) is a better solution,
then I'll always prefer that.
Jun 27 '08 #14
On Wed, 23 Apr 2008 at 18:27:55, in comp.lang.javascript, Dr J R
Stockton wrote:

<snip>
>Aside : is there a representation, known to browsers, for the old-style
s as in "Ye olde faufage-fhop" in which I used f instead?
The HTML character entities don't include a long s, but they do include
the integral sign, &int; , which might do instead. It works in IE5.5+.
Failing that, you'll have to use a small image instead.

Incidentally, some early English printing displayed 'the' as a y with a
dot over it. Presumably a hand-written 'ye' was often abbreviated that
way.

John
--
John Harris
Jun 27 '08 #15
In comp.lang.javascript message <op***************@metallium.lan>, Wed,
23 Apr 2008 22:12:34, Rik Wasmus <lu************@hotmail.composted:
>On Wed, 23 Apr 2008 19:27:55 +0200, Dr J R Stockton
<jr*@merlyn.demon.co.ukwrote:
>Aside : is there a representation, known to browsers, for the old-style
s as in "Ye olde faufage-fhop" in which I used f instead?

&#x17F; or ſ
Thanks. I'm copying from a Book of 1662. Tested OK in IE7, FF2, Op9,
Sf2. In <URL:http://www.merlyn.demon.co.uk/estr-bcp.htm#PTs>.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jun 27 '08 #16
On Thu, 24 Apr 2008 12:27:22 +0200, John G Harris
<jo**@nospam.demon.co.ukwrote:
On Wed, 23 Apr 2008 at 18:27:55, in comp.lang.javascript, Dr J R
Stockton wrote:

<snip>
>Aside : is there a representation, known to browsers, for the old-style
s as in "Ye olde faufage-fhop" in which I used f instead?

The HTML character entities don't include a long s, but they do include
the integral sign, &int; , which might do instead. It works in IE5.5+.
Failing that, you'll have to use a small image instead.

Incidentally, some early English printing displayed 'the' as a y with a
dot over it. Presumably a hand-written 'ye' was often abbreviated that
way.
'y' was a substitution for the thorn symbol (þ), for which there was
no letter in print AFAIK. It would still be pronounced as 'th', making a
fool out of those saying a literal 'ye' nowadays. As far as I know, no
diacretics were added to this, but they were to the thorn character, which
can look like a y in written form, see
<http://en.wikipedia.org/wiki/Þ#Abbreviations>.
--
Rik Wasmus
Jun 27 '08 #17
In article <fu*************@news.t-online.com>, Stevo <no@mail.invalid>
wrote:
Dr J R Stockton wrote:
Those who decline to learn simple RegExp use are wasting their own
future time, unless they decide to give up programming in favour of a
less intellectual pursuit, such as politics.

An OP who needs to ask such a question should do likewise.

Is there any need for that?

There are a lot of us that don't consider RegExp a good alternative.

Imagine how much code is being run in the background to parse a RegExp
string. In this particular example, the code that Gregor provided, which
was a simple array split, followed by a simple concatenation, was (a)
extremely easy to understand, and (2) doesn't involve very complex
regexp parsing in the background. The code that handles the split and
concatenation code behind the scenes we can all imagine is fairly
trivial. The same can't be said for a RegExp parser.

I prefer two lines of code that are easy to understand and as far as
complexity goes, what you see is pretty much all that's happening. The
RegExp version is not obvious if you're unfamiliar, and involves too big
an overhead in the background. Certainly too big for this particular
case. If you're parsing a humongous length string then the RegExp
overhead would pay off because the code you'd have to write wouldn't be
just two lines.
Then the regexp would be *really* incomprehensible :-)
I have used RegExp code before, I always fully comment what it does
though, and if the alternative (as in this case) is a better solution,
then I'll always prefer that.
Dead right. Let's have some respect for future maintainers.
Jun 27 '08 #18
Dr J R Stockton <jr*@merlyn.demon.co.ukwrites:
Aside : is there a representation, known to browsers, for the old-style
s as in "Ye olde faufage-fhop" in which I used f instead?
You're looking for the unicode "LATIN SMALL LETTER LONG S" - &#x017f;

Cheers,
J.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #19
On Thu, 24 Apr 2008 at 20:02:17, in comp.lang.javascript, Rik Wasmus
wrote:
>On Thu, 24 Apr 2008 12:27:22 +0200, John G Harris
<jo**@nospam.demon.co.ukwrote:
<snip>
>Incidentally, some early English printing displayed 'the' as a y with
a dot over it. Presumably a hand-written 'ye' was often abbreviated
that way.

'y' was a substitution for the thorn symbol (þ), for which there
was no letter in print AFAIK.
I'm following a facsimile of one of the first books to be printed in
England. There were no letters in print at all until the printer carved
them himself or had them carved to his design. Presumably the printer
made thorn look like a y because that's what his customers were familiar
with in hand-written books.

>It would still be pronounced as 'th', making a fool out of those
saying a literal 'ye' nowadays. As far as I know, no diacretics were
added to this, but they were to the thorn character, which can look
like a y in written form, see <http://en.wikipedia.org/wiki/Þ#Abbrevia
tions>.
The dot over y is not an accent. It's an abbreviation, just as 'at' is
abbreviated as @ and first is abbreviated as 1st.

John
--
John Harris
Jun 27 '08 #20

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

Similar topics

13
by: JustSomeGuy | last post by:
I have two object types ClassA and ClassB class ClassA { public: int data; operator ClassB() { ClassB b; b.data = data + 1; return (b);
6
by: DarkKobold | last post by:
I am writting a keyboard emulator for the pic microcontroller. Unfortunately, after watching it on the oscilliscope, it is not transmitting the right data. The clock signal on B1 is working...
1
by: Jim | last post by:
Here is a snipet of the code. // State object for receiving data from remote device. public class StateObject { // Client socket. public Socket workSocket = null; // Size of receive buffer....
4
by: Jarod | last post by:
Hey In my intelisense ( VS 2005 ) , when I type for example foreach I have selected in intelisense list snipet called foreach, how to chose it so it will display the snippet ? I know there is a...
4
by: Mairhtin O'Feannag | last post by:
Hello, I'm obviously a newbie, and since I detest re-inventing the wheel, can someone show me/give me a snippet that will verify that an input string is a numeric value? I'm using DB2 and would...
6
by: bratiskovci | last post by:
1. How do I change the program so that the program does not terminate after completing one conversion. Instead, the program should continue to convert values until the user indicates that he/she...
7
by: Bigs | last post by:
Ok, I have been working on a Linear Equation program that will draw a line on my graph. But, I am not sure how to set up the y=mx+b in Java to return the (x1,y1) and (x2, y2) using only the slope and...
0
by: baldrex | last post by:
hello again, I have already gotten to the pdf file, however it hangs at the save as screen. What I am looking for is a snipet of code that will allow me to print to the pdf and auto save it to...
1
by: sigkill9 | last post by:
I'm new to Python and am trying to figure out how to streamline the code at bottom to get it more simple but am having trouble. I was hoping that someone here could help me out? The program I am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.