Solved

How to display datetime in Classic ASP

Posted on 2013-01-29
7
643 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Query Syntax Error 9 34
Extract XML Data from using TSQL 5 32
Usage Scenarios for Extended Events? 1 12
Update in Sql 7 12
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

14 Experts available now in Live!

Get 1:1 Help Now