Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question dd/mm/yy --> mm/dd/yy

    dd/mm/yy --> mm/dd/yy
    Any known script for this?

    Or better, any DateDiff script that works with the dd/mm/yy format?

    thanks

  • #2
    New Coder
    Join Date
    Apr 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    function dateDiff(date1, date2)
    	{
    	// EXPECTS 2 DATES IN dd/mm/yy or dd/mm/yyyy FORMAT
    	var date1Array = date1.split('/');
    	var date2Array = date2.split('/');
    
    	// IF LENGTH OF DATE IS 2 CHARS CONVERT TO 4 CHARS
    	if (date1Array[2].length == 2)
    		{
    		if (date1Array[2] > 70)
    			date1Array[2] = '19'+date1Array[2];
    		else
    			date1Array[2] = '20'+date1Array[2];
    		}
    
    	if (date2Array[2].length == 2)
    		{
    		if (date2Array[2] > 70)
    			date2Array[2] = '19'+date2Array[2];
    		else
    			date2Array[2] = '20'+date2Array[2];
    		}
    
    	// CREATE DATE OBJECTS
    	var date1Obj = new Date(date1Array[2], date1Array[1]-1, date1Array[0]);
    	var date2Obj = new Date(date2Array[2], date2Array[1]-1, date2Array[0]);
    
    	var oneDay=1000*60*60*24;
    	
    	// CONVERT DATE OBJECTS TO TIMESTAMPS
    	var date1Stamp = date1Obj.getTime();
    	var date2Stamp = date2Obj.getTime();
    
    	// CALCULATE NUMBER OF DAYS BETWEEN DATES
    	if (date1Stamp > date2Stamp)
    		alert(Math.ceil((date1Stamp - date2Stamp) / oneDay));
    	else
    		alert(Math.ceil((date2Stamp - date1Stamp) / oneDay));
    	}
    Hope this helps

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That's great! Thanks alot!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •