Javascript time formatting issue

Anonymous
timer Asked: Jul 17th, 2013
account_balance_wallet $5

Question Description

I am new, please be patient.

Reporting software I am using pulls in a start and end time from a database into two separate columns. (the data in the database is from a multi-field calculated column.) 

In the reporting software (Entrinsik Informer) I want to format the time so that if the start time and end time are both am (or pm), it will shorten the start time to only the hour (no minutes, no :, no AM/PM)

For example:

Before formatting

Start time End time
7:00 AM - 11:00 AM

WHAT I WANT
after formatting

Start Time End Time
7 - 11:00AM

Likewise if both the start and end are pm timer 1:00pm - 3:00pm should look like 1-3:00pm.


If the start time is am and the end time is a pm, then nothing should occur. 7:00am-1:00pm leave it as is.

The reporting software I am using only accepts Javascript.

Also the reporting software only uses the main javascript code, it doesn't need all the header, title, etc that you would normally need for a webpage. for example the software recognizes this: 


//which does what the function i want, but only on the current time not a database stored time value

var d = new Date();
d.getHours() 



But does not recognize this formatting:

<html>
<head>
<title>hello</title>
</head>
<body>
var d = new Date();
d.getHours()
</body>
</html>


I have read through numerous forums, but none show how to change time from 7:00 AM to 7

Any assistance would be greatly appreciated.

Tutor Answer

patelmaulesh007
School: UT Austin

hi

I think you can use date to string method in javascript.



flag Report DMCA
Review

Anonymous
Thanks, good work

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors