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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Format in ASP 1

Status
Not open for further replies.

pupadu

Programmer
Mar 18, 2005
24
US
Hello everyone and anyone.

I know that there is a real simple solution to this beginner's problem but for the life of me, I can't find the solution for this.

I'm using ASP with an SQL database. I need to convert datetime data such as "17:00:00" into "5:00 PM". I've tried "vbshorttime" but I get "05:00:00 PM".

Any and all help is and will be greatly appreciated.
 
try
Code:
<%
timenow="17:00:00"
response.write formatdatetime(timenow,vbLongTime)
%>
 
if it still does has a 0 you can use this function
Code:
function fixtime(strtime)
strtemp=FormatDateTime(strtime, vbLongTime)
if left(strtemp,1)="0" then 
strtemp=mid(strtemp,2)
end if
fixtime=strtemp
end function
test it like this
Code:
timenow="17:00:00"
response.write fixtime(timenow)
 
Thanks so much steven290 for responding. I do appreciate your help. However, this didn't work. It's displaying as "5:00:00 PM".

Any other ideas? I'm wide open to them, believe me. :)
 
oh didn't see that you wanted to remove the seconds, give me a few and i'll get back to you
 
try something like this, i didnt test it

function fixtime(strtime)
strtemp=FormatDateTime(strtime, vbLongTime)
if left(strtemp,1)="0" then
strtemp=mid(strtemp,2)
end if
arrtime=split(strtemp,":")
fixtime= arrtime(0)&":"&arrtime(1)&" "&right(arrtime(2),2)
end function
 
Steven290, you are amazing! Thank you, thank you, thank you so much. I was thinking about splitting the time but I was way off by not thinking about the LEFT and MID functions. Again, thank you so much! I absolutely love this forum. I know it's corny but I just had to get that off my chest. :)
 
Glad it worked out for you.


please provide stars to those that helped you.
 
Steven290, you just earned yourself a star from me. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top