Avatar
Please consider registering
guest
sp_LogInOut Log Insp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSSsp_topic_old
Time Conversion problem
Avatar
raihan84
Member
Members
March 24, 2011 - 1:45 pm
Member Since: March 4, 2011
Forum Posts: 12
sp_UserOfflineSmall Offline

Hello guys,

I have got a problem. I wanna change an integer number to corresponding hours and minutes. For example, if you enter 100 then it will return 1:40 hours, that is one hour and 40 minutes.

I like to have and user defined functions or macro code..............

Please help me with the conversion ASAP.

Thanks
Raihan

Avatar
Chad Johnson
Mod
Members
March 24, 2011 - 3:52 pm
Member Since: August 11, 2011
Forum Posts: 867
sp_UserOfflineSmall Offline

So...I'm not a macro coder, but your logic would look like this:

x = input number

if x < 60 return "x minutes"
else
y = x / 60 --gives number of hours
z = x-y -- gives number of minutes
return "y hours and z minutes"

Avatar
raihan84
Member
Members
March 24, 2011 - 4:20 pm
Member Since: March 4, 2011
Forum Posts: 12
sp_UserOfflineSmall Offline

[quote="Ziggie":1bahq5ps]So...I'm not a macro coder, but your logic would look like this:

x = input number

if x < 60 return "x minutes"
else
y = x / 60 --gives number of hours
z = x-y -- gives number of minutes
return "y hours and z minutes"[/quote:1bahq5ps]

Yeh, you have got my logic but I wanna return as y:z format, where y is hours and z is min.

Avatar
raihan84
Member
Members
March 24, 2011 - 4:49 pm
Member Since: March 4, 2011
Forum Posts: 12
sp_UserOfflineSmall Offline

I have got two ways to solve this problem.................................

Let A1 = 100, now if we want to return value at A2 cell then at formula bar I have written the code

1. [code:3h4zvu1y]CONCATENATE(FLOOR(A1/60,1), ":",(A1/60-FLOOR(A1/60,1))*60)[/code:3h4zvu1y]
2. [code:3h4zvu1y]INT(A1/60)&":"&MOD(A1,60)[/code:3h4zvu1y]

in return in cell A2 i got 1:40.

Does anybody know any other formulas?

Avatar
Chad Johnson
Mod
Members
March 24, 2011 - 6:39 pm
Member Since: August 11, 2011
Forum Posts: 867
sp_UserOfflineSmall Offline

This will handle values under 60:
[code:29xp43hs]=IF(A1>60,CONCATENATE(TRUNC(A1/60), ":", A1-(TRUNC(A1/60)*60)),CONCATENATE("0:", A1))[/code:29xp43hs]

Avatar
raihan84
Member
Members
March 24, 2011 - 11:42 pm
Member Since: March 4, 2011
Forum Posts: 12
sp_UserOfflineSmall Offline

[quote="Ziggie":1rdot3s4]This will handle values under 60:
[code:1rdot3s4]=IF(A1>60,CONCATENATE(TRUNC(A1/60), ":", A1-(TRUNC(A1/60)*60)),CONCATENATE("0:", A1))[/code:1rdot3s4][/quote:1rdot3s4]

Thanks Zig

Avatar
raihan84
Member
Members
March 25, 2011 - 1:32 am
Member Since: March 4, 2011
Forum Posts: 12
sp_UserOfflineSmall Offline

This could be another formula.....................

[code:1hx7264w]TEXT(FLOOR(A1/60,1),"00")&":"&TEXT(MOD(A1,60),"00")[/code:1hx7264w]

Thanks

Avatar
Carol Bratt
Mod
Moderators
March 25, 2011 - 10:54 am
Member Since: August 11, 2011
Forum Posts: 67
sp_UserOfflineSmall Offline

If you have a time in a decimal format, i.e. an integer and a fraction, e.g. 2.5 hours (2 and a half hours) and you want to convert to a standard time format 02:30 (2 hours and 30 minutes), then you can use a formula based on the TIME function with the following syntax:
TIME(hours,minutes,seconds)
Example:
We have a decimal time 2.5 in cell A2. we can use the following formula to convert it to a standard time:
=TIME(INT(A2);(A2-INT(A2))*60;0)

Avatar
raihan84
Member
Members
March 25, 2011 - 2:49 pm
Member Since: March 4, 2011
Forum Posts: 12
sp_UserOfflineSmall Offline

[quote="Carol Bratt":1ccho2kg]If you have a time in a decimal format, i.e. an integer and a fraction, e.g. 2.5 hours (2 and a half hours) and you want to convert to a standard time format 02:30 (2 hours and 30 minutes), then you can use a formula based on the TIME function with the following syntax:
TIME(hours,minutes,seconds)
Example:
We have a decimal time 2.5 in cell A2. we can use the following formula to convert it to a standard time:
=TIME(INT(A2);(A2-INT(A2))*60;0)

Avatar
Carol Bratt
Mod
Moderators
March 25, 2011 - 3:10 pm
Member Since: August 11, 2011
Forum Posts: 67
sp_UserOfflineSmall Offline

Glad I could help!

Forum Timezone: America/Indiana/Indianapolis
Most Users Ever Online: 2303
Currently Online: twicekidneys
Guest(s) 50
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Chad Johnson: 867
Mindblower: 677
carbonterry2: 356
Flying Dutchman: 278
grr: 211
Member Stats:
Guest Posters: 11
Members: 3229
Moderators: 7
Admins: 3
Forum Stats:
Groups: 8
Forums: 20
Topics: 1954
Posts: 13563
Newest Members:
instaproapk, mousetesteronline, keshamatt, Patriciabin, MattOwens
Moderators: Carol Bratt: 67, dandl: 740, Jason Shuffield: 1, Jim Canfield: 8, Terry Hollett: 0, Stuart Berg: 0, John Durso: 0
Administrators: Jim Hillier: 2709, Richard Pedersen: 210, David Hartsock: 1117
Scroll to Top

WHY NOT SUBSCRIBE TO OUR NEWSLETTER?

Get great content like this delivered to your inbox!

It's free, convenient, and delivered right to your inbox! We do not spam and we will not share your address. Period!