Display Datetime on classic ASP page

Posted on 2012-08-14
Last Modified: 2012-08-14
On my classic asp page the time (e.g. 12:30) is displayed like this:


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
Question by:baxtalo
    LVL 1

    Assisted Solution

    This would probably be the easiest way in order to display the date and time in the format that you are looking for.


    Author Comment

    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?
    LVL 31

    Accepted Solution

    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;"
        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%>
    LVL 31

    Expert Comment

    OR, rather, you already have the shortime example ... use it:

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

    Author Closing Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
    Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.

    760 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

    11 Experts available now in Live!

    Get 1:1 Help Now