Forum Discussion
megbennett
Jan 06, 2022Copper Contributor
Converting Year/Month/Week/Day/Hour to Days
Hello, I cannot figure out the formula(s) to convert a single cell that contains '1 Year 8 Months 1 Week 5 Days 17 Hours 30 Minutes' into number of days (would like to round up to a full day, and my...
HansVogelaar
Jan 06, 2022MVP
It's not possible to produce an exact result, because 8 months can be 242, 243, 244 or 245 days depending on the start date: February to October is 242 days in a non-leap year, and March to November is 245 days.
You could use the following custom VBA function:
Function Convert2Days(s As String) As Long
Dim a() As String
a = Split(s)
Convert2Days = Application.RoundUp(365 * a(0) + 365 / 12 * a(2) + 7 * a(4) + a(6) + a(8) / 24 + a(10) / 1440, 0)
End Function
With a string such as 1 Year 8 Months 1 Week 5 Days 17 Hours 30 Minutes in for example D2, the approximate number of days is
=Convert2Days(D2)
This can be filled down if required.