Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-11-2008, 01:44 AM   PM User | #1
anys
New to the CF scene

 
Join Date: Jun 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
anys is an unknown quantity at this point
format date

hye.. i want to ask about a format date, i have 1 form which is the date that i using is in format d/m/y, but then when i fill up the form, in database the date it will get 0000/00/00, this is because in database the format date is Y/m/d. So how can i get the format date in d/m/y. Because i want format date in d/m/y.
anys is offline   Reply With Quote
Old 06-11-2008, 02:56 AM   PM User | #2
mrhoo
Regular Coder

 
Join Date: Mar 2006
Posts: 708
Thanks: 30
Thanked 127 Times in 118 Posts
mrhoo will become famous soon enoughmrhoo will become famous soon enough
If you validate the input from your form on the server, convert it there.
or use a dummy input (with no name attribute) and convert it to a hidden field (with a name).
Convert it by validating it before you submit the form.
Code:
dummydate.onchange= function(e){
	e= window.event || e;
	e= e.target || e.srcElement;
	var who= document.getElementsByName('hiddendate');
	var D= e.value.split(/\D+/);
	try{
		var A= [D[2]*1,D[1]-1,D[0]*1];
		D= new Date(A[0],A[1],A[2]);
		if(D.getFullYear()== A[0] && D.getMonth()+1== A[1] && D.getDate()== A[2]){
			who.value= A.join('/');
			return true;
		}
	}
	catch(er){
		throw 'Bad Date- '+e.value;
	}
	return false;
}
mrhoo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:01 PM.


Advertisement
Log in to turn off these ads.