Solved

How to display datetime in Classic ASP

Posted on 2013-01-29
7
652 Views
Last Modified: 2013-01-29
Please take a look at the code below:

<%If IsNull(rs("SunIn")) or (rs("SunIn"))="1900-01-01 00:00:00.000" Then %>
SUN
<%else%>
<%=FormatDateTime(rs("SunIn"),vbshorttime)%>
<%end if%>

I'm trying to display the word "SUN" on my Classic ASP page when the record in the SQL Server database is null or 1900-01-01 00:00:00.000
When the record is null the word SUN is displayed correctly. My problem is that when the record is 1900-01-01 00:00:00.000 the word SUN is not displayed, instead the time is displayed like this: 00:00
How could I have SUN displayed instead? Thanks for your help.
0
Comment
Question by:baxtalo
  • 3
  • 3
7 Comments
 
LVL 11

Expert Comment

by:David Kroll
ID: 38831792
Just a guess, but try this:

<%If IsNull(rs("SunIn")) or (rs("SunIn")="1900-01-01 00:00:00.000") Then %>
SUN
<%else%>
<%=FormatDateTime(rs("SunIn"),vbshorttime)%>
<%end if%>


Just moved one of the ) to the end of the date
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38831849
<%
Mesg="SUN"
if not IsNull(rs("SunIn")) then
     if left(rs("SunIn"),4)<>"1900" then
        Mesg=FormatDateTime(rs("SunIn"),vbshorttime)
    end if
end if
response.write Mesg
%>
0
 

Author Comment

by:baxtalo
ID: 38831922
Unfortunately none of the above worked. In both cases the "1900-01-01 00:00:00.000" record was returned as "00:00"
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38831980
<%
response.write "The Data is "&rs("SunIn")&"<br>"
Mesg="SUN"
if not IsNull(rs("SunIn")) then
     response.write "There is data<br>"
     if left(cstr(rs("SunIn")),4)<>"1900" then
        Mesg=FormatDateTime(rs("SunIn"),vbshorttime)
    end if
end if
response.write Mesg
%>
0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 38831988
<%
response.write "The Data is "&rs("SunIn")&"<br>"
Mesg="SUN"
if not IsNull(rs("SunIn")) then
     response.write "There is data<br>"
     if year(rs("SunIn"))<>"1900" then
        Mesg=FormatDateTime(rs("SunIn"),vbshorttime)
    end if
end if
response.write Mesg
%>
0
 

Author Comment

by:baxtalo
ID: 38832014
The Data is 1/1/1900
There is data

Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'cstr'
0
 

Author Closing Comment

by:baxtalo
ID: 38832023
Oh, great...
It worked; thank you very much...
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question