Javascript time formatting issue

Question Description

I need help with a Programming question. All explanations and answers will be used to help me learn.

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

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();

But does not recognize this formatting:

var d = new Date();

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.

Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer


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

UT Austin

Solid work, thanks.

The tutor was great. I’m satisfied with the service.

Goes above and beyond expectations !


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