• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

how to subtract date and time in the same cell|General Excel Questions & Answers|Excel Forum|My Online Training Hub

You are here: Home / how to subtract date and time in the same cell|General Excel Questions & Answers|Excel Forum|My Online Training Hub

vba course banner

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumGeneral Excel Questions & Answe…how to subtract date and time in th…
sp_PrintTopic sp_TopicIcon
how to subtract date and time in the same cell
Avatar
DinaMar Mar

New Member
Members
Level 0
Forum Posts: 1
Member Since:
July 23, 2021
sp_UserOfflineSmall Offline
1
July 23, 2021 - 1:18 am
sp_Permalink sp_Print

The attached file is a downloaded report. It shows students who take and finish courses. the start and finish time don't show whether is AM or PM. I need to calculate the difference between the finish date and start date, as well as the difference between the finish time and start time. The score 100 means the student successfully finished the course and it shows the finished time. However, I would be also interested in knowing how to calculate the time spent on those unfinished courses. Would it be possible to do? 

What have I done so far?

- I used right and left formulas to cut off the weird numbers at the end of the date/time cell. 

- I did also used right and left formulas to extract date, and then I subtracted the finish date from start date, of course only for the students who finished a course.

- for some reason I couldn't use the right and left formula to calculate the difference between finish time and start time, it showed weird results, so I did use the MOD formula. =MOD(F7-D7,1).  

Please note, I had to convert text to values in some of the steps above. All the above worked to some point, until I filtered the start date/time by months, and use the ALT plus semi colon ; to extract only filtered values, copied and pasted the filtered rows and values looked totally off. 

My goal is to be able to show in one report the monthly time spent for each student, and compare the progress by month. I'd would create pivot tables and hopefully a dashboard. 

I would be very thankful if somebody can look into this and be able to suggest a much effective approach to my dilemma. 

Sincerely,

Dina

sp_AnswersTopicSeeAnswer See Answer
Avatar
Anders Sehlstedt
Eskilstuna, Sweden

VIP
Members


Trusted Members
Level 3
Forum Posts: 873
Member Since:
December 7, 2016
sp_UserOfflineSmall Offline
2
July 23, 2021 - 6:23 am
sp_Permalink sp_Print sp_EditHistory

Hello Dina,

Welcome to MOTH.

You can find more useful information here on how to work with date/time in Excel.

If you are familiar to Power Query I suggest you use that tool to clean up your data, below is suggested steps to clean the data using formulas and helper columns, see attached file.

NOTE: As I work in Swedish regional settings I use semi colon (;) as separator in the below exampel formulas, you need to change those to comma (,) if you want to copy and paste the formulas. Also in my TEXT formula I use t to get the hours, you need to change that to h to get correct values.

  1.  As you have done yourself, you need to clean up the start and finish date/time values. Example formula below is to clean up the start date/time in your sample file, column D. The result will give you a correct Excel date/time value as a number, which helps when to calculate the difference in days and hours.

    =IFERROR(DATEVALUE(LEFT($D2;FIND(".";$D2)-1))+TIMEVALUE(LEFT($D2;FIND(".";$D2)-1));"")

  2.  Next is to calculate the difference between the dates and times. In this example I add some helping text to the days and time values. In this example the date/time is converted back to text.

    =IFERROR(
    IF(INT(H2-G2)=0;
    TEXT(H2-G2;"t")&" hour(s) "&TEXT(H2-G2;"m")&" minute(s)";
    INT(H2-G2)&" day(s) "&TEXT(H2-G2;"t")&" hour(s) "&TEXT(H2-G2;"m")&" minute(s)");
    "")

    Another example with no helping text.

    =IFERROR(
    IF(INT(H2-G2)=0;
    TEXT(H2-G2;"tt:mm");
    INT(H2-G2)&" "&TEXT(H2-G2;"tt:mm"));
    "")

sp_AnswersTopicAnswer
Answers Post
sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Catalin Bombea, John Kobiela, Malcolm Sawyer
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 216
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Melanie Ford
Isaac Felbah
Adele Glover
Hitesh Asrani
Rohan Abraham
Anthony van Riessen
Erlinda Eloriaga
Abisola Ogundele
MARTYN STERRY
Rahim Lakhani
Forum Stats:
Groups: 3
Forums: 24
Topics: 6356
Posts: 27793

 

Member Stats:
Guest Posters: 49
Members: 32324
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.