Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9129247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:42:07+00:00 2026-06-17T07:42:07+00:00

I have two time strings; eg. 09:11 and 17:22 on the same day (format

  • 0

I have two time strings; eg. “09:11” and “17:22” on the same day (format is hh:mm). How do I calculate the time difference in minutes between these two?

Can the standard date library do this?

Example:

#!/bin/bash

MPHR=60    # Minutes per hour.

CURRENT=$(date -u -d '2007-09-01 17:30:24' '+%F %T.%N %Z')
TARGET=$(date -u -d'2007-12-25 12:30:00' '+%F %T.%N %Z')

MINUTES=$(( $(diff) / $MPHR ))

Is there a simpler way of doing this given the hour and minute in hh:mm

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:42:08+00:00Added an answer on June 17, 2026 at 7:42 am

    A pure bash solution :

    old=09:11
    new=17:22
    
    # feeding variables by using read and splitting with IFS
    IFS=: read old_hour old_min <<< "$old"
    IFS=: read hour min <<< "$new"
    
    # convert hours to minutes
    # the 10# is there to avoid errors with leading zeros
    # by telling bash that we use base 10
    total_old_minutes=$((10#$old_hour*60 + 10#$old_min))
    total_minutes=$((10#$hour*60 + 10#$min))
    
    echo "the difference is $((total_minutes - total_old_minutes)) minutes"
    

    Another solution using date (we work with hour/minutes, so the date is not important)

    old=09:11
    new=17:22
    
    IFS=: read old_hour old_min <<< "$old"
    IFS=: read hour min <<< "$new"
    
    # convert the date "1970-01-01 hour:min:00" in seconds from Unix EPOCH time
    sec_old=$(date -d "1970-01-01 $old_hour:$old_min:00" +%s)
    sec_new=$(date -d "1970-01-01 $hour:$min:00" +%s)
    
    echo "the difference is $(( (sec_new - sec_old) / 60)) minutes"
    

    See http://en.wikipedia.org/wiki/Unix_time

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, I have file with the following strings: string.Format({0},{1}, Having \Two\ On The Same
I have two arrays with time values in them in this format. 00:00:00 which
I have two information and want them to be displayed at the same time.
I have a function that creates time intervals between two time marks. The function
I have two select fields in a form. Every time one of these select
I have two images, both taken at the same time from the same detector.
I'm trying to find out if two strings I have are the same, for
We have two sets, A and B. Each one of these sets include strings.
I have a class with two parameters. One is the update time in Minutes
I have two controls whos code are run time rendered as below: ctl00_PlaceHolderMain_SPWebPartManager_g_3c1ba10a_23ec_4ab5_b303_18f8bd7ee7e7_ctl00_gdvItinerary_ctl03_txtTravelDate ctl00_PlaceHolderMain_SPWebPartManager_g_3c1ba10a_23ec_4ab5_b303_18f8bd7ee7e7_ctl00_gdvItinerary_ctl04_txtTravelDate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.