Change date format (years, days, hours) to days

Fjura

New Member
Joined
Jan 17, 2017
Messages
5
Hello,

May I ask if someone knows how I could change this kind of format (years, days, hours) for example: "220 y 344 d 12 h" to a number of days?



So "220 y 344 d 12 h" would be "80644,50"

thanks!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
are you assuming 365 days for every year and not including leap years ?

what happens if there are no days or no years
would that be

220 y 0 d 0 h
 
Upvote 0
are you assuming 365 days for every year and not including leap years ?

what happens if there are no days or no years
would that be

220 y 0 d 0 h

365 for all, yea in that case it would be as you wrote.
 
Upvote 0
It seems to me that the biggest challenge you face is to parse the string ans extract the actual numbers from it. If you want a pure cell function solution, you could go with a very complicated string search function, like this (assuming your YDH-string is in A1):

Code:
=VALUE(LEFT(A1,FIND("y",A1)-1))*365+VALUE(MID(A1,FIND("y",A1)+2,FIND("d",A1)-FIND("y",A1)-2))+VALUE(MID(A1,FIND("d",A1)+2,LEN(A1)-FIND("d",A1)-3))/24

However, a simpler solution might be to split your column of YDH-strings using the 'Text to Columns' method. If you split it by white space you'll end up with years, days, and hours in three distinct columns which makes the calculations much easier.
 
Last edited:
Upvote 0
EDIT - I see exactly the same type of formula has already been suggested


try

=((LEFT(A1,FIND("y",A1,1)-2)*1 )*365)+(MID(A1,FIND("y",A1,1)+1,(FIND("d",A1,1)-1)-(FIND("y",A1,1)+1))*1) + ((MID(A1,(FIND("d",A1,1)+1),LEN(A1)-(FIND("d",A1,1)+1))*1)/24)

Where A1 is the Cell with the value in
 
Last edited:
Upvote 0
I have slightly different solution if want to try:

If all your data is in Column A
I will highlight column A, select "Text to Columns" from the data Tab
Leave on "Delimited width" and select next
Tick only the "space" delimiter and click next once again
Choose the columns that's have "y", "d" and "h" and select the format "Do not import column (skip)
Set Destination as =$B$1
Click Finish.
You now have years, days and hours in separate columns.
A simple formula in E1 will give you the result you want: =(B1*365)+C1+(D1/24)
 
Last edited:
Upvote 0
I have slightly different solution if want to try:

If all your data is in Column A
I will highlight column A, select "Text to Columns" from the data Tab
Select "Delimited" and select next
Tick only the "space" delimiter and click next once again
Choose the columns that's have "y", "d" and "h" and select the format "Do not import column (skip)
Set Destination as =$B$1
Click Finish.
You now have years, days and hours in separate columns.
A simple formula in E1 will give you the result you want: =(B1*365)+C1+(D1/24)
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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