?
Solved

Display Datetime on classic ASP page

Posted on 2012-08-14
5
Medium Priority
?
1,226 Views
Last Modified: 2012-08-14
On my classic asp page the time (e.g. 12:30) is displayed like this:

<%=FormatDateTime(rs("SunOut"),vbshorttime)%>

I'm trying to have the time displayed with the following code, but this returns the values like this: 1/1/1900 12:30:00 PM


<%If rs2.BOF and rs2.EOF then Response.Write "&nbsp;" Else response.write rs2.fields("SunIn") End If%>


How could I modify it in order to have the same results as with the vbshorttime example?

Thank you for your help
0
Comment
Question by:baxtalo
  • 2
  • 2
5 Comments
 
LVL 1

Assisted Solution

by:ktromp1
ktromp1 earned 1000 total points
ID: 38293529
This would probably be the easiest way in order to display the date and time in the format that you are looking for.

<%response.write(FormatDateTime(date(),vbshortdate))
response.write(FormatDateTime(now(),vblongtime))%>
0
 

Author Comment

by:baxtalo
ID: 38293615
The field in my database is named SunIn and it's supposed to return the time in 12:30 format.
I'm trying to have it returned with the BOF EOF statement, and I don't know how to insert the "vbshorttime" part in the code, in order to have the time displayed in the 12:30 format. This is the code I'm using:

<%If rs2.BOF and rs2.EOF then Response.Write "&nbsp;" Else response.write rs2.fields("SunOut") End If%>

The time is returned in the following format:
1/1/1900 12:30:00 PM

I would just need the 12:30 part. How can that be accomplished?
0
 
LVL 31

Accepted Solution

by:
alorentz earned 1000 total points
ID: 38293690
Assuming you always have a value, and that the format is 1/1/1900 12:30:00 PM
<%If rs2.BOF and rs2.EOF then
     Response.Write "&nbsp;"
Else
    arr = split(rs2.fields("SunOut"), " ") 'split value on the space into arr
    response.write arr(1) 'display only the 2nd part of the array
End If%>
0
 
LVL 31

Expert Comment

by:alorentz
ID: 38293714
OR, rather, you already have the shortime example ... use it:

<%If rs2.BOF and rs2.EOF then
     Response.Write "&nbsp;"
Else
    response.write formatdatetime(rs2.fields("SunOut"), 4)
End If%>
0
 

Author Closing Comment

by:baxtalo
ID: 38293723
Thank you very much, your comments were very helpful. I actually did the following and my problem is solved:

<%If rs2.BOF and rs2.EOF then Response.Write "&nbsp;" Else response.write (FormatDateTime(rs2.fields("SunIn"),vbshorttime)) End If%>
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses

594 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