Solved

How to display datetime in Classic ASP

Posted on 2013-01-29
7
647 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now