Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display MS Access Time field in web page

Status
Not open for further replies.

werosen1

Programmer
Mar 30, 2006
16
US
I am trying to query an Access 2002 database from my asp page and have the data in the 'Time' field displayed in the custom format that I designated when I built the Access table. I am using the following format in Access: h:nnam/pm to return 8:30am.

When I query the 'Time' field from my page and display it in the browser, it returns 8:30:00 AM.

I am at a loss as to a resolution.

Can anyone help?
 
Rewrite the output using DATEPART. If you were using it frequently, use a function.

Something like below. I'm sure the AM/PM part can be written more elegantly. This is just a rought idea.

Code:
DATEPART("h",mytime) & ":" & DATEPART("n",mytime)

IF mytime > "12:00" THEN 
response.write "AM"
ELSE 
response.write "PM"
END IF

[/end]

I borrowed/wrote a much more flexible function to deal with all date parts and variants thereof. Very useful. I can dig it up if you want.  Allows me to just write an output mask.
 
Thanks for the reply. About 2Am this mornig I ran across and elegant solution. Here it is:

SELECT FORMAT(Time ,'h:nnam/pm') as fTime
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top