Link to home
Start Free TrialLog in
Avatar of Stefan Motz
Stefan MotzFlag for United States of America

asked on

Classic ASP Error when displaying time from database

Hi Experts,
I'm trying to display a time entry from my Teradata database. I format it like this:
<%=FormatDateTime(rs("Arrival_Time"),vbshorttime)%>
The page displays it nicely, but when the time entry in the database is
1/1/0001 00:00:00
I get an error on my ASP page:
error '80020009'

How can this problem be solved?
I appreciate your help.
SOLUTION
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stefan Motz

ASKER

I've tried the following, but unfortunately it displayed the same error:

<td><%If rs("Arrival_Time") > "1/1/1970" Then%><%=FormatDateTime(rs("Arrival_Time"),vbshorttime)%><%else%>-<%end if%></td>

All times are displayed on my ASP page, except for the ones that show as 1/1/0001 00:00:00 in the database.
Hmm.

Maybe try...
   If CDate(rs("Arrival_Time")) > CDate("1/1/1970")
           'display time
     Else
          'display some message
     End If


It's been a while since I've worked in classic ASP!
I've tried it, but received the same error. When I run the query in SQL Assistant everything is returned. When I run the same on my classic ASP page, the 1/1/0001 00:00:00 values display the error.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much for your attention. It turned out that I didn't have to change anything on my ASP page. I had to change the SQL and cast Arrival_Time as a char(19)  

CAST(CAST(Arrival_Time AS FORMAT 'HH:MI') AS CHAR(19))

For some reason my ASP page didn't like timestamps but it works fine when casting the result as a char.