Getting the current year

T

Tim Slattery

This should be simple. I code this:

Dim thisYear

currDate = Now
thisYear = Year(currDate)

And get a "type mismatch" error on the last line. I get the same thing
if I use Date instead of Now. What's wrong with this?
 
M

Martin Honnen

Tim said:
This should be simple. I code this:

Dim thisYear

currDate = Now
thisYear = Year(currDate)

And get a "type mismatch" error on the last line. I get the same thing
if I use Date instead of Now. What's wrong with this?

Do you happen to have your own sub named 'Year' defined elsewhere?
Otherwise I can't see anything wrong.
 
B

Bob Barrows

Tim said:
This should be simple. I code this:

Dim thisYear

currDate = Now
thisYear = Year(currDate)

And get a "type mismatch" error on the last line. I get the same thing
if I use Date instead of Now. What's wrong with this?
Works fine for me. There must be something else on your page causing the
problem. Prove it to yourself. Create a test page with nothing but these
lines in it:
<%
Dim thisYear

currDate = Now
thisYear = Year(currDate)
Response.Write thisYear
%>
 
S

Steven Cheng

Hi Tim,

Regarding on the gettting current year code, I've created a test asp page
and run it. It seems the code can execute correctly. Here is a complete
test page I used:

===============================
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<%

Dim thisYear, thisMonth, thisDay

currDate = Date()
thisYear = Year(currDate)
thisMonth = Month(currDate)
thisDay = Day(currDate)

Response.Write("<br/>This Year: " & thisYear & ", This Month: " & thisMonth
& ", This Day: " & thisDay)


currDate = Now
thisYear = Year(currDate)
thisMonth = Month(currDate)
thisDay = Day(currDate)

Response.Write("<br/>This Year: " & thisYear & ", This Month: " & thisMonth
& ", This Day: " & thisDay)
%>


</body>
</html>
====================================

As for the problem you encounterd, have you used any other server-side
extension that may cause the problem? For example, is the page an ASP.NET
page or intercepted by ASP.NET runtime that cause the error?

If there is anything I missed, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).


--------------------
 
T

Tim Slattery

Hi Tim,

Regarding on the gettting current year code, I've created a test asp page
and run it. It seems the code can execute correctly. Here is a complete
test page I used:

Thanks for all the responses. There was nothing wrong with the code I
posted. I was working on an existing ASP page, and there was a
variable named "year" that was defined and used elsewhere in the page.
 
S

Steven Cheng

Thanks for your reply Tim,

So the problem is caused by that custom variable (also named "Year") and
the problem went away after you removed it, correct?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,217
Latest member
IRMNikole

Latest Threads

Top