The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> CALCULATING TIME DIFFERENCE BETWEEN TWO DIFFERENT TIME INPUT FIELDS WITHOUT DATE INTERVENTION
shankar from vizag
post Sep 7 2019, 01:00 AM
Post #1


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



GREETINGS

I HAVE TWO INPUT TEXTBOXES WHICH POPULATES TIME IN hh:mm tt (eg: 11:28 AM format).

I WANT TO DISPLAY THE DURATION BETWEEN THE ABOVE TWO TIMES IN THE THIRD TEXTBOX IN MINUTES.

I TRIED IN MANY WAYS, BUT FAILED.

KINDLY GUIDE ME IN THIS REGARD.

REGARDS
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
CharlesEF
post Sep 21 2019, 06:23 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Better yet, just show me the format of the time element. Is it HH:MM:SS or what? I really don't want to install jQuery or bootstrap.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Sep 22 2019, 01:18 AM
Post #3


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



QUOTE(CharlesEF @ Sep 21 2019, 04:53 PM) *

Better yet, just show me the format of the time element. Is it HH:MM:SS or what? I really don't want to install jQuery or bootstrap.


Dear Charles

The required time format is HH:mm along with AM/PM

eg: 11:48 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
johnwalsh1020
post Jan 7 2020, 01:56 AM
Post #4





Group: Members
Posts: 1
Joined: 7-January 20
Member No.: 27,114



Why you can not use toLocaleDateString() inbuilt javascript function. This function is capable to give you return as per your format. Here is my code snippet to use it.

CODE
// Parse our locale string to [date, time]
var date = new Date().toLocaleString('en-US',{hour12:false}).split(" ");

// Now we can access our time at date[1], and monthdayyear @ date[0]
var time = date[1];
var mdy = date[0];

// We then parse  the mdy into parts
mdy = mdy.split('/');
var month = parseInt(mdy[0]);
var day = parseInt(mdy[1]);
var year = parseInt(mdy[2]);

// Putting it all together
var formattedDate = year + '-' + month + '-' + day + ' ' + time;


Default Date.toLocaleString() returns is a format of:

MM/DD/YYYY, HH:MM:SS

Morover, you can use Date() function to create an date object with the current date. If you want to get date in specific format you might need to refer Date and time in JavaScript article. Here is snipprt for the date object.

CODE
var today = new Date();
var date = today.getFullYear() + '-' + (today.getMonth()+1) + '-' + today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var date_time = date + ' ' + time;


Thank you

This post has been edited by johnwalsh1020: Jan 7 2020, 01:56 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
shankar from vizag   CALCULATING TIME DIFFERENCE BETWEEN TWO DIFFERENT TIME INPUT FIELDS WITHOUT DATE INTERVENTION   Sep 7 2019, 01:00 AM
CharlesEF   What have you tried? Show your code if you want h...   Sep 7 2019, 01:22 AM
shankar from vizag   What have you tried? Show your code if you want ...   Sep 8 2019, 05:36 AM
CharlesEF   Read this page, it might help.   Sep 7 2019, 02:13 PM
CharlesEF   This really isn't the way to do date math. Bu...   Sep 8 2019, 01:13 PM
shankar from vizag   This really isn't the way to do date math. B...   Sep 10 2019, 08:21 AM
shankar from vizag   This really isn't the way to do date math. B...   Sep 10 2019, 11:26 AM
CharlesEF   Since you posted no new code I can't see your ...   Sep 10 2019, 01:17 PM
CharlesEF   Oh oh, I left some bad code in my answer (overlook...   Sep 11 2019, 12:51 PM
shankar from vizag   Oh oh, I left some bad code in my answer (overloo...   Sep 14 2019, 05:02 AM
CharlesEF   You didn't attach any Javascript files. I don...   Sep 14 2019, 06:38 PM
shankar from vizag   You didn't attach any Javascript files. I do...   Sep 15 2019, 08:34 AM
CharlesEF   Oh, that error is unknown to me. I don't know...   Sep 15 2019, 12:38 PM
CharlesEF   Maybe you can try changing the .js to .txt and upl...   Sep 15 2019, 03:30 PM
shankar from vizag   Maybe you can try changing the .js to .txt and up...   Sep 20 2019, 11:41 PM
shankar from vizag   Maybe you can try changing the .js to .txt and up...   Sep 20 2019, 11:47 PM
CharlesEF   Better yet, just show me the format of the time el...   Sep 21 2019, 06:23 AM
shankar from vizag   Better yet, just show me the format of the time e...   Sep 22 2019, 01:18 AM
johnwalsh1020   Why you can not use toLocaleDateString() inbuilt j...   Jan 7 2020, 01:56 AM
CharlesEF   Attached is the example you wanted. I just did a ...   Sep 22 2019, 09:11 AM


Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 27th April 2024 - 11:41 AM