Date d-m-yy to dd-mm-yyyy

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jan 2008
Posts: 10
Reputation: mohanvamsi_18 is an unknown quantity at this point 
Solved Threads: 0
mohanvamsi_18 mohanvamsi_18 is offline Offline
Newbie Poster

Date d-m-yy to dd-mm-yyyy

 
0
  #1
Aug 19th, 2009
Thanks in advance...

My question is.. I have one text box there user types the date as follows (d-m-yy)

5-4-09 or 15-3-94

how can i convert them into exact (dd-mm-yyyy)

05-04-2009 or 15-03-1994

is there any 'javascript' code to convert the given date into my desired formt...

please help me...
Last edited by mohanvamsi_18; Aug 19th, 2009 at 7:42 am. Reason: forget to put javascript
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Date d-m-yy to dd-mm-yyyy

 
0
  #2
Aug 20th, 2009
Hi,

try this one:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta http-equiv="Content-Script-Type" content="text/javascript">
  7. <title>www.daniweb.com</title>
  8. <script type="text/javascript">
  9. <!--
  10. var d = document;
  11. var validate = function( field ) {
  12. var today = new Date();
  13. var field = ( typeof( field ) === "object" ) ? field : d.getElementById( field );
  14. if ( field && field.value.length ) {
  15. var hold = [];
  16. var stamp = [ ( today.getMonth() + 1 ), today.getDate(), today.getFullYear() ];
  17. var date = field.value.split("-");
  18. for ( var i = 0; i < date.length; i++ ) {
  19. var num = Number( date[ i ] );
  20. hold[ i ] = num;
  21. hold[ i ] = (( hold[ i ] > stamp[ i ] || !hold[ i ] ) ? stamp[ i ] : hold[ i ] );
  22. hold[ i ] = (( hold[ i ] < 10 ) ? "0" : "" ) + hold[ i ];
  23. } (( hold[ 2 ] && String( hold[ 2 ] ).length < 4 ) ? hold[ 2 ] = stamp[ 2 ] : void( 0 ));
  24. field.value = hold.join("-");
  25. }
  26. };
  27.  
  28. // -->
  29. </script>
  30. </head>
  31. <body>
  32. <div>
  33. <form action="#" id="testform">
  34. <div>Date Format: <em>mm-dd-yyyy</em><br>
  35. <input type="text" id="datefield" name="datefield" size="10" maxlength="10" value="" onchange="validate( this );">
  36. </div>
  37. </form>
  38. </div>
  39. </body>
  40. </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 10
Reputation: mohanvamsi_18 is an unknown quantity at this point 
Solved Threads: 0
mohanvamsi_18 mohanvamsi_18 is offline Offline
Newbie Poster

Re: Date d-m-yy to dd-mm-yyyy

 
0
  #3
Aug 20th, 2009
TanQ for your reply...

I tried it for some date like ... 8-6-94 but it gives 08-06-2009

12-5-86 it gives 08-06-2009 even it is not today date also...

but any way tanQ for your contribution...

i got a way from your code...

i will implement it.. and post it..

TanQ very much..
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Date d-m-yy to dd-mm-yyyy

 
0
  #4
Aug 20th, 2009
Hi,

i made it to react, that if you provide year lower than a usual 4 digit format, then it will automatically converted to the current year. The format must be on this entry 08-06-1994 to able for that to work.
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC