Parse html code for dates with vbscript

I'm looking to extract dates from an HTML page using vbscript. Here's an example of the raw data:

<TABLE class=contract_table cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD class=contract_header width="36%">Description</TD>
<TD class=contract_header width="16%">Provider</TD>
<TD class=contract_header width="16%">Start Date</TD>
<TD class=contract_header width="16%">End Date</TD>
<TD class=contract_header style="BORDER-RIGHT-WIDTH: 0px" width="16%">Days Left</TD></TR>
<TR>
<TD class=contract_oddrow>UNY</TD>
<TD class=contract_oddrow>5/12/2008</TD>
<TD class=contract_oddrow>5/12/2010</TD>
<TD class=contract_oddrow style="BORDER-RIGHT-WIDTH: 0px">553</TD></TR>

I'm looking for code that will find and return the most recent date found in the data. The date will either appear as MM/DD/YYYY or M/DD/YYYY.

Thanks.
LVL 5
mrpez1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
the attached code will give you 5/12/2010. If you are interested in 5/12/2008 then change the else if to Greater than instead:
ElseIf CDate(lastDate) > CDate(Trim(cell.innerHTML)) Then
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title></title>
<script type="text/vbscript">
Function recentDate
	Dim t
	Set td = document.getElementsByTagName("td")
	Dim lastDate
	lastDate = False
	For Each cell in td
		If IsDate(cell.innerHTML) Then
			If VarType(lastDate) = vbBoolean Then
				lastDate = Trim(cell.innerHTML)
			ElseIf CDate(lastDate) < CDate(Trim(cell.innerHTML)) Then
				lastDate = Trim(cell.innerHTML)
			End If
		End If
	Next
	recentDate = lastDate
End Function 
Sub init
	msgbox recentDate()
End Sub
</script>
</head>
<body onload="call init()">
<TABLE class=contract_table cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD class=contract_header width="36%">Description</TD>
<TD class=contract_header width="16%">Provider</TD>
<TD class=contract_header width="16%">Start Date</TD>
<TD class=contract_header width="16%">End Date</TD>
<TD class=contract_header style="BORDER-RIGHT-WIDTH: 0px" width="16%">Days Left</TD></TR>
<TR>
<TD class=contract_oddrow>UNY</TD>
<TD class=contract_oddrow>5/12/2008</TD>
<TD class=contract_oddrow>5/12/2010</TD>
<TD class=contract_oddrow style="BORDER-RIGHT-WIDTH: 0px">553</TD></TR>
</TBODY>
</TABLE>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.