Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Time Format in ASP/Javascript

Explorer ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

I'm trying to format time in an ASP/javascript page in Dreamweaver that is being pulled from an Access 2003 database. The default format has seconds displayed which I do not want. In Dreamweaver you can choose formatting, however, none of the choices are what I need. What I want is non-military time, no seconds displayed and I do want AM/PM. So, this is what I would like to see:

4:45 PM

The Dreamweaver formatting gives me the following:

04:45:00 PM

04:45:00

16:45

None of these are useful to me. Does anyone know how I can get my time to display correctly?

thanks,
Winona
TOPICS
Server side applications

Views

298
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

You should be able to use some code from this page and turn it into what you
need.

http://www.web-source.net/web_development/javascript_date.htm

It's not all applicable as you do not want to create the date object, as
that code does, but the principles you need to employ are the same for
getting the hour and minute portions out of your stored date and also
working out the AM PM part and displaying that too.
I hope that helps.
Cheers,
Rob
http://robgt.com/ [Tutorials and Extensions]
Firebox stuff: http://robgt.com/firebox
Skype stuff: http://robgt.com/skype
SatNav stuff: http://robgt.com/satnav



Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 17, 2006 Aug 17, 2006

Copy link to clipboard

Copied

Unfortunately I'm a novice and I don't know enough about javascript to pull it together. I'm using Dreamweaver 8, ASP/javascript and an Access 2003 database. This is the field being pulled in using ASP:

<%=(appointment.Fields.Item("AP_AppointTime").Value)%>

My question is how would I write the javascript to use that field as a variable then how would I call in the javascript?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 22, 2006 Aug 22, 2006

Copy link to clipboard

Copied

LATEST
You should be able to drop this code onto the page where you want the time
to appear.
This is just a quick and dirty chunk of code that I put together and have
not tested.
Please bear in mind that I do not code in ServerSide JavaScript (I use
VBScript) so the code might not be accurate...

<%
var now = (appointment.Fields.Item("AP_AppointTime").Value)
var hour = now.getHours();
var minute = now.getMinutes();
var ampm = "AM";
if (hour>11){
ampm = "PM";
}
response.write(hour + ":" + minute + " " + ampm);
%>

I hope that helps.
Cheers,
Rob
http://robgt.com/ [Tutorials and Extensions]
Firebox stuff: http://robgt.com/firebox
Skype stuff: http://robgt.com/skype
SatNav stuff: http://robgt.com/satnav



Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines