Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Adding a variable time field (24 format) and a variable datetime field (m/d/yy h:MM tt) to produce result in another field

Please help! I am a very novice JavaScript user and have scoured the forums trying to find an answer to my problem:

I have two fields that are variable I am trying to add them together in a separate field. One field (TotHr) is in HH:MM format, and the other is a datetime field (DTin1) that is in m/d/yy h:MM tt format. I need the output to read in the same format as the datetime field. This will be utilized on various consoles throughout my work, so I would like to not use a library like moment.js.

Here is what I have so far:

var date = new Date();
var dateMil = date.getTime("DTin1");
var timePeriod = ("TotHr");

var parts = timePeriod.split(/:/);
var timePeriodMil = (parseInt(parts[0], 10) * 60 * 60 * 1000) +
                (parseInt(parts[1], 10) * 60 * 1000) + 
                (parseInt(parts[2], 10) * 1000);

var newDate = new Date();
newDate.setTime(dateMil + timePeriodMil);

console.log(newDate);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are many ways to do it in JavaScript. A simple way is to use some library e.g. the following code uses moment.js library.

const { duration } = require('moment')
const moment = require('moment-timezone')

let strDuration = "10:30"
let strDateTime = "9/6/21 5:10 am"
let format = 'M/D/YY h:m a'

dur = moment.duration(strDuration)
dt = new moment(strDateTime, format)

result = dt.add(dur).tz('Europe/London').format(format)

console.log(result)

Output:

9/6/21 3:40 pm
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!