We help IT Professionals succeed at work.

Display Datetime on classic ASP page

baxtalo
baxtalo asked
on
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
Comment
Watch Question

Commented:
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))%>

Author

Commented:
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?
Top Expert 2004
Commented:
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%>
Top Expert 2004

Commented:
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%>

Author

Commented:
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%>

Explore More ContentExplore courses, solutions, and other research materials related to this topic.