View Full Version : Date
flash
10-28-2002, 09:44 AM
Hello.
I need to show the current month and only the month using ASP. I need to use Javascript rather than VBScript.
Any help would be great!
Thanks.
glenngv
10-28-2002, 09:55 AM
you can use a combination of both:
<%
dMonth=Month(Date())
%>
<script language="javascript">
var currentMonth = <%=dMonth%>;
alert(currentMonth);
</script>
flash
10-28-2002, 10:01 AM
Hey.
Thanks for the help but I get the error:
Error Type:
Microsoft JScript runtime (0x800A1391)
'dMonth' is undefined
flash
10-28-2002, 10:02 AM
I was going to use this code:
<SCRIPT LANGUAGE=JAVASCRIPT>
var now = new Date();
var yy = now.getYear();
var mm = now.getMonth();
var dd = now.getDate();
var dy = now.getDay();
var days = new Array("Sunday", "Monday", "Tueday", "Wednesday", "Thursday", "Friday", "Saturday");
var mons = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "December");
if ((dd == 1) || (dd == 21) || (dd == 31)){en = "st"};
else if ((dd == 2) || (dd == 22)){en = "nd"};
else if ((dd == 3) || (dd == 23)){en = "rd"};
else{en = "th"};
document.write(mons[mm])
</SCRIPT>
For some reason it displays this month as november. When I change the comps date to another month it shows the correct settings.
:confused:
glenngv
10-28-2002, 10:06 AM
ahh you're using jscript.
var mm = now.getMonth()+1;
This method returns an integer (0 for January thru 11 for December) that represents the month for the specified date.
flash
10-28-2002, 10:50 AM
Thats not really any good.
If I add +1 then it makes the month December.
If I add -1 it makes the month September.
:confused:
I gotta try to work this out lol
Thanks for your help though :thumbsup:
OK. It's VBscript, buth maybe it helps (you or someonelse)
monthnum=Month(now)
monthname=MonthName(monthnum)
response.write("Month =" & monthname)
glenngv
10-29-2002, 01:06 AM
ok. so you dont have problem at all, you dont have to add or minus 1 since you have array of months like below:
var mm = now.getMonth();
...
var mons = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "December");
...
alert(mm);
document.write(mons[mm])
this should display the correct month.
try alerting mm
but hey! you don't have October in there! :)
that's where the problem is.
whammy
10-29-2002, 01:13 AM
What's October? I thought that word sounded familiar, and that "Oct" had something to do with the number "10" in latin, but I think it may have been stolen by halloween daemons.
;)
whammy
10-29-2002, 01:19 AM
P.S. If you just want to show the current month (all kidding aside), just do something like:
MsgBox MonthName(Month(Now()))
(Save that as "monthname.vbs" on your computer)
Of course this is easily translated to ASP:
Response.Write(MonthName(Month(Now())))
P.P.S. You actually DON'T have to use JScript as opposed to VBScript IF you are using this script server-side - they are interchangeable in ASP, as long as you tell the server which language you're using.
To be honest with you, as friendly as the date functions are in VB, I'd definitely consider using them instead. :)
<script language="VBScript" runat="server">
Response.Write(MonthName(Month(Now())))
</script>
:D
christrinder
12-11-2002, 12:38 PM
Hi Guys,
Been reading through the posts above, but is there a more simple way for the server to throw out the month in words? i.e. at the moment I use the following code in my drop down menu...
<option value="<% Response.Write Month(Date()) %>" select><% Response.Write Month(Date()) %></option>
but what would I need to add to it to make it read December? I've seen FormatDate(CurrDate,2) type codes about, is there something like that I can use?
Thanks in advance
Chris
P.S. (an after thought) is there any calendar function that can return the number of days in the current month, more specifically the number of working days?
whammy
12-11-2002, 11:42 PM
This help?:
<% Response.Buffer = True %>
<%
Dim indent, indent2, i
indent = " "
indent2 = indent & indent
%>
<html>
<head></head>
<body>
<form id="monthform" action="months.asp" method="post">
<select name="month">
<%
For i = 1 to 12
Response.Write(indent2 & "<option value=""" & Right("00" & i,2) & """")
If Right("00" & i,2) = Request.Form("month") Then Response.Write(" selected=""selected""")
Response.Write(">" & MonthName(i) & "</option>")
If i < 12 Then Response.Write(vbCrLf)
Next
%>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>
:D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.