Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving month name 1

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
I have a variable that is pulling a short month from a form:

var strCurrMonth = document.thisform.txtMonth.value (i.e Jun)

How can I convert it to an integer reperesentation of the month (6 or 5 if zero-based)
I need to get the previous month's string name from this, something like this:


var intCurrMonth = getMonth(strMonth)
var intPrevMonth = intCurrMonth - 1
var strPrevMonth = getMonthName(intPrevMonth)
 
Here's one way of doing it:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>title test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

var a = monthNames[5];  //Jun
var b = new Date(a + " 1, 2000");

var intCurrMonth = b.getMonth()
b.setMonth(b.getMonth() - 1);
var intPrevMonth = b.getMonth();
var strPrevMonth = monthNames[intPrevMonth];

alert("intCurrMonth: " + intCurrMonth);
alert("intPrevMonth: " + intPrevMonth);
alert("strPrevMonth: " + strPrevMonth);

</script>
<style type="text/css"></style>
</head>
<body>

</body>
</html>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top