Formatting Date and Time in cell while also counting down days?

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
Here's my sheet:

countdown.png


Here's the formula in E56:

Excel Formula:
=C56-D56


Here's the formatting in E56:

Excel Formula:
d "Days" h "Hours" m "Minutes" ss "Seconds"

How can I show the "Days" number as the number of days until the deadline? So it should look like this:

145 Days 22 Hours 15 Minutes 56 Seconds

It should switch from 145 Days to 144 when it rolls over.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I think that the only way you can do it is to split the value and show it as a string with the text function.

Formula looks right but I'm not able to test it at present.

Excel Formula:
=INT(C56-D56)&" days "&TEXT(MOD(C56-D56,1),"h"" hours ""m"" minutes ""s"" seconds""")
 
Upvote 0
Solution
are you expecting the countdown to occur automatically - with a function it will only update if the sheet calculates using F9
you will need some sort of action to trigger the calc - so maybe VBA - which i'm sorry - but i cannot provide

different cells - but using jasonb75 formula for you to see

Cell Formulas
RangeFormula
B1B1=NOW()
D1D1=INT(A1-B1)&" days "&TEXT(MOD(A1-B1,1),"h"" hours ""m"" minutes ""s"" seconds""")
 
Upvote 0
I found a workable solution that required some different coding. Here's the formula I used to subtract the current date and time from the deadline date and time:

Excel Formula:
=DATEDIF(B1,B2,"d")& " Days  "&TEXT(B2-B1,"h")&" Hours  "&TEXT(B2-B1,"m")&" Minutes  "&TEXT(B2-B1,"s")&" Seconds"

...and here's the vba used to refresh the current date and time. I call Recalc when the Workbook is opened and Disable when it is closed.

VBA Code:
Dim SchedRecalc As Date
Sub Recalc()
With Range("CurrentDateTime")
.Value = Format(Date, "m/d/yyyy") & " " & Format(Time, "h:mm:ss AM/PM")
End With
Call SetTime
End Sub
Sub SetTime()
SchedRecalc = Now + TimeValue("00:00:01")
Application.OnTime SchedRecalc, "Recalc"
End Sub
Sub Disable()
On Error Resume Next
Application.OnTime EarliestTime:=SchedRecalc, Procedure:="Recalc", Schedule:=False
End Sub

countdown2.png


Thanks for everyone's help and I hope this is useful to someone else in the future.
 
Upvote 0
Slight correction to the formula above. Should be this so that minutes are correct:

Excel Formula:
=DATEDIF(B1,B2,"d")& " Days  "&TEXT(B2-B1,"h")&" Hours  "&RIGHT(TEXT(B2-B1,"hh: m"),2)&" Minutes  "&TEXT(B2-B1,"s")&" Seconds"
 
Upvote 0
Or you could use the one that I suggested instead of making it more complicated than necessary 🤔
 
Upvote 0
Or you could use the one that I suggested instead of making it more complicated than necessary 🤔

Both give the desired result. Yours's is more concise so that's the one I'll use. Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top