Solved

How to display datetime in Classic ASP

Posted on 2013-01-29
7
659 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help Required 3 108
Query Syntax 17 43
VBScript on Html 15 48
ASP Classic and Parsing XML single and Inner Nodes with URL does not work, with physical address to xml file works. 12 20
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.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.

828 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