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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dateadd not working

Status
Not open for further replies.

fluxdemon

MIS
Nov 5, 2002
89
US
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "9/31/2004"]'

is the error I am getting. I tried using datavalue and cdate to change the concatated string to a date. All of the functions are included below.


**** code below ****
<% @LANGUAGE = "VBScript" %>
<% Response.Buffer = True %>


<html>
<style>
<!--
.onMonth{ width: 150px; cursor: pointer; }
.onDay{ width: 150px; background-color: #5555ff; color: #ffffff; cursor: pointer; }
.offMonth{ width: 150px; background-color: #cccccc; cursor: pointer; }
.whiteText{ color: #ffffff; font-weight: 600;}
-->
</style>

<body>
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<form id="calendar" name="calendar" method="post" action="calendar.asp">
<td width="240" height="100%">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="1">
<tr><td></td></tr>
</table>
</td>
<td height="100%">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><% call monthDropDown() %></td>
<td>&nbsp;</td>
<td><% call yearDropDown() %></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" height="100%">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="1">
<%call writeWeekdayNames()%><%call largeCalendar()%>
</table>
</td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>


<%sub monthDropDown()%>
<select id="monthDropDown" name="monthDropDown" value="<%=month(now)%>" onkeypress="if(event.keyCode==13) document.calendar.submit();">
<%dim pValue
if request.form("monthDropDown")>"" then
pValue=request.form("monthDropDown")
else
pValue=month(now)
end if
%>

<% for count = 1 to 12 %>
<% if(pValue=count) then %>
<option value="<%=count%>" selected><%=monthname(count)%></option>
<% else %>
<option value="<%=count%>"><%=monthname(count)%></option>
<% end if %>
<% next %>
</select>
<%end sub%>

<%sub yearDropDown()%>
<select id="yearDropDown" name="yearDropDown" value="<%=year(now)%>" onkeypress="if(event.keyCode==13) document.calendar.submit();">
<%dim pValue
if request.form("yearDropDown")>"" then
pValue=request.form("yearDropDown")
else
pValue=year(now)
end if
%>

<% for count = year(now) - 20 to year(now) + 20 %>
<% if(pValue=count) then %>
<option value="<%=count%>" selected><%=count%></option>
<% else %>
<option value="<%=count%>"><%=count%></option>
<% end if %>
<% next %>
</select>
<%end sub%>

<%sub writeWeekdayNames()%>
<% for count = 1 to 7 %>
<td class="day" height="1"><%=weekdayname(count,true)%></td>
<% next %>
<%response.write vbCrLf%>
<%end sub%>

<% sub offMonth_Day(pValue) %>
<td class="offMonth">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<% if (pValue>15) then %>
<tr><td width="100%" height="100%" onclick="alert('<%=formatOffMonthDate(pValue,-1)%>');"></td></tr>
<tr><td width="100%" align="right" onclick="alert('<%=formatOffMonthDate(pValue,-1)%>');"><%=pValue%></td></tr>
<% else %>
<tr><td width="100%" height="100%" onclick="alert('<%=formatOffMonthDate(pValue,1)%>');"></td></tr>
<tr><td width="100%" align="right" onclick="alert('<%=formatOffMonthDate(pValue,1)%>');"><%=pValue%></td></tr>
<% end if %>
</table>
</td>
<% end sub %>

<%sub onMonth_Day(pValue)%>
<%if date=formatDate(pValue) then%>
<td class="onDay">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td width="100%" height="100%" class="whiteText" onclick="alert('<%=formatDate(pValue)%>');"></td></tr>
<tr><td width="100%" align="right" class="whiteText" onclick="alert('<%=formatDate(pValue)%>');"><%=pValue%></td></tr>
</table>
</td>
<%else%>
<td class="onMonth">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td width="100%" height="100%" onclick="alert('<%=formatDate(pValue)%>');"></td></tr>
<tr><td width="100%" align="right" onclick="alert('<%=formatDate(pValue)%>');"><%=pValue%></td></tr>
</table>
</td>
<%end if%>
<%end sub%>

<% sub beginRow() %>
<tr>
<% end sub %>

<% sub endRow() %>
</tr>
<% end sub %>


<%

function formatOffMonthDate(pValue,pModifier)
if request.form("monthDropDown")>"" then
lvMonth=request.form("monthDropDown")
else
lvMonth=month(now)
end if

if request.form("yearDropDown")>"" then
lvYear=request.form("yearDropDown")
else
lvYear=year(now)
end if

formatOffMonthDate=dateadd("m", pModifier,lvMonth & "/" & pValue & "/" & lvYear)
end function

function formatDate(pValue)
if request.form("monthDropDown")>"" then
vMonth=request.form("monthDropDown")
else
vMonth=month(now)
end if

if request.form("yearDropDown")>"" then
vYear=request.form("yearDropDown")
else
vYear=year(now)
end if

formatDate=vMonth & "/" & pValue & "/" & vYear
end function

function LC_writeMonth(count,pValue1,pValue2,monthState)
response.write vbCrLf
for maketable=pValue1 to pValue2
select case count
case 1
call beginRow()
if monthState=false then
call offMonth_Day(maketable)
else
call onMonth_Day(maketable)
end if
count=count+1
case 7
if monthState=false then
call offMonth_Day(maketable)
else
call onMonth_Day(maketable)
end if
call endRow()
count=1
case else
if monthState=false then
call offMonth_Day(maketable)
else
call onMonth_Day(maketable)
end if
count=count+1
end select
next
LC_writeMonth=count
end function


sub largeCalendar()
dim pValue
if request.form("monthDropDown")>"" or request.form("yearDropDown")>"" then
pValue=request.form("monthDropDown") & "/1/" & request.form("yearDropDown")
else
pValue=date
end if

dim daysLastMonth
dim daysThisMonth: daysThisMonth=daysInMonth(month(pValue))
dim daysNextMonth

if month(pValue)-1=0 then
daysLastMonth=daysInMonth(12)
else
daysLastMonth=daysInMonth(month(pValue)-1)
end if

if month(pValue)+1=13 then
daysNextMonth=daysInMonth(1)
else
daysNextMonth=daysInMonth(month(pValue)+1)
end if

dim numDaysLastMonth: numDaysLastMonth=weekday(datevalue(month(pValue) & "/1/" & year(pValue)))+5
dim numDaysNextMonth: numDaysNextMonth=48-(daysThisMonth + numDaysLastMonth)
dim count: count=1

response.write vbCrLf
count=LC_writeMonth(count,daysLastMonth-numDaysLastMonth,daysLastMonth,false)
count=LC_writeMonth(count,1,daysThisMonth,true)
call LC_writeMonth(count,1,numDaysNextMonth,false)
response.write vbCrLf
end sub

function daysInMonth(pValue)
select case pValue
case 1,3,5,7,8,10,12:
daysInMonth = 31
case 2:
if (iYear mod 4 = 0) and ((iYear mod 100 <> 0) or (iYear mod 400 = 0)) then
daysInMonth = 29
else
daysInMonth = 28
end if
case 4,6,9,11:
daysInMonth = 30
end select
end function

%>
 
It's interpreting
Code:
lvMonth & "/" & pValue & "/" & lvYear
as a string, so you'd convert it to a date with CDate(), like this:
Code:
CDate(lvMonth & "/" & pValue & "/" & lvYear)
 
I have already tried cdate(lvMonth & "/" & pValue & "/" & lvYear) and this is the error it gives me:

Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'cdate'
 
Then that means that there's something wrong with lvMonth, pValue, or lvYear, or two of them, or all three. After you've calculated them (any time before the DateAdd), Response.Write them, followed by a Response.Flush. You'll see what they are and should be able to figure it out from there.
 
Also, if someone changed the Date/Time format for the machine your on then that could be the issue, someone did tat to me before and it was expecting dd/mm/yyyy instead of mm/dd/yyyy. So if you sent it 12/31/2004 then you would get an error because it would try to interpret 31 as the month.

Another option for date conversion is to use DateSerial:
Code:
myDate = DateSerial(yearVar,monthVar,dayVar)
Since that function doesn't change with the changing date formats if it fails it isbecause one of the variables is bad, not because someone messed with the server settings.

-T

barcode_1.gif
 
I have made some progress... since there isn't thirty-one days in September it throws an error. (before dateadd works with it) So, I put an if statement around it. Now it works except for 31 Aug alerts nothing, I think further testing would turn up other omissions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top