alvinchua Posted February 1, 2008 Share Posted February 1, 2008 i need HELP ! how to convert a month like January in a combo box into a value ===> 01 Febuary in a combo box into a value ===> 02 (this is because i am letting people to select the month as string in a combo box like Jan, Feb, March, bla bla... and later on i need to convert it into numeric to calculate days between two dates ) pls advice.. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted February 2, 2008 Share Posted February 2, 2008 You need to reference the dateObject "getMonth()". Basic Example: <script language="javascript"> var d = new Date(); var month = d.getMonth(); alert(month); </script> Quote Link to comment Share on other sites More sharing options...
alvinchua Posted February 3, 2008 Author Share Posted February 3, 2008 i no need to get the new date .. now i have a variable storing the current selected month .. let say var month ( is storing January) how i can convert the january to 01 ?? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted February 3, 2008 Share Posted February 3, 2008 <script language="javascript"> var month="January"; switch(month) { case "January": var month="01"; break; case "February": var month="02"; break; case "March": var month="03"; break; case "April": var month="04"; break; case "May": var month="05"; break; case "June": var month="06"; break; case "July": var month="07"; break; case "August": var month="08"; break; case "September": var month="09"; break; case "October": var month="10"; break; case "November": var month="11"; break; case "December": var month="12"; break; } alert(month); // remove this - demo purposes only </script> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.