Results 1 to 4 of 4

Thread: Date format mm/dd/yyyy to dd/mm/yyyy

  1. #1
    Join Date
    May 2008
    Posts
    222

    Date format mm/dd/yyyy to dd/mm/yyyy

    Hi guys
    I am new to javascript and I am trying to write a program for changing a date. Does any one know how to change the date format from mm/dd/yyyy to dd/mm/yyyy. I am using the pregnancy calculator here from
    Code:
    http://javascript.internet.com/math-related/pregnancy.html
    Any advice on this or solution on this will be highly appreciated. Thanks in advance.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Date format mm/dd/yyyy to dd/mm/yyyy

    Hi
    I am posting a code that will change a date format. Just go through the program it will help you.
    Code:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">	
    
    	function in(){
    
    		var nd = "11/24/2009";
    		var nd = nd.replace(/(\d{2})\/(\d{2})\/(\d{4})/, "$2/$1/$3");
    		alert(nd);	
    	}
    
    	navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', in, false) : addEventListener('load', in, false);	
    
    </script>
    Any more queries post back.

  3. #3
    Join Date
    May 2008
    Posts
    222

    Re: Date format mm/dd/yyyy to dd/mm/yyyy

    Hi
    Thanks for the quick reply. I have tried your code sorry but it is not working. I even tried to add the following, but still I have problems.
    Code:
    <script type="text/javascript">
    
    function in(){
    
    var nd = "11/24/2009";
    var nd = nd.replace(/(\d{2})\/(\d{2})\/(\d{4})/, "$2/$1/$3");
    alert(nd);
    
    }
    navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', in, false) : addEventListener('load', in, false);
    
    </script>
    any suggestion on this.

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Date format mm/dd/yyyy to dd/mm/yyyy

    Hi
    The above posted code is really nice. The only one import line in this code which you have to go through.
    Code:
    nd = nd.replace(/(\d{2})\/(\d{2})\/(\d{4})/, "$2/$1/$3");
    I am posting the code it is a simple example. Hope it may help you.
    Code:
    function cDate(nd)
    {
    //this is the symbol that separates months, days and years and you can set it to anything, just pick your separator
    var separator = "/";
    
    //puts mm, dd and yyyy into an array
    var ndarr = nd.split(separator);
    
    //saves each argument of the array into a string starting with the day
    nd = ndarr[1] + separator + ndarr[0] + separator + ndarr[2];
    
    return nd;
    }

Similar Threads

  1. Using date format in JSP
    By KAMANA in forum Software Development
    Replies: 6
    Last Post: 29-07-2010, 10:32 AM
  2. Problem in date format
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 04:38 AM
  3. Insert date format in SQL via ASP
    By Bansi_WADIA in forum Software Development
    Replies: 4
    Last Post: 04-12-2009, 10:56 PM
  4. Changing the date format
    By Uzair in forum Customize Desktop
    Replies: 3
    Last Post: 03-04-2009, 12:44 PM
  5. whenCreated Date Format
    By settler in forum Active Directory
    Replies: 3
    Last Post: 04-01-2007, 08:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,621,655.47871 seconds with 17 queries