Tải bản đầy đủ - 0 (trang)
Hack 23. Show Elapsed Time as Days and Hours

Hack 23. Show Elapsed Time as Days and Hours

Tải bản đầy đủ - 0trang

Thefirstpartoftheformulaaddsupallhours,dividesthisby

24(thenumberofhoursinaday),androundsthenumber

downtothenearestinteger.Thesecondpartoftheformula

usestheMODfunction(moduloarithmetic),whichtakestwo

parameters,dividesthefirstparameterbythesecond,then

returnstheremainder.Theresultwilldisplayas"7days18

hours,"asshowninFigure3-17.

Thedevelopmenttasksspreadsheetsumsthelistof

taskstoatotalof186hours



HackingtheHack

Thisapproachworksfine,butyoucanmakeitmorereadable

throughtheuseofanamedrange,aneasy-to-rememberlabel

assignedtoaspecificrangeofcells.InGoogleSpreadsheets,

switchtotheFormulastab(locatedtowardthetopofthepage),

click"Rangenames,"andselect"Definenew."Nameyourrange

byusingalabellike"hours_spent"andselecttherangeofcells

(B2:B12).(SeeFigure3-18.)Savethenewrangeandclosethe

dialog,andyou'rereadytoreplaceyourexistingformulawith

thefollowing:

CodeView:



=INT(SUM(hours_spent)/24)&"days"&MOD(SUM(hours_spent



























Or,toreturnthenumberofweeks,youcanusethefollowing

formula,whichexpandstheformerone:



=INT(SUM(hours_spent)/24/7)&"weeks"&

INT(MOD(SUM(hours_spent)/24,7))&"days"&MOD(SUM(ho

24)&"hours"



Alternatively,youmayalsowanttoprintanoverviewofthe

totalhoursspentinmultipleformats,suchasseconds,minutes,

hours,days,weeks,andyears.Youcannameresultcellsof

calculationsusingtherangenamesfeaturetosimplifythisstep,

aspicturedinFigure3-19,whichalsoshowstheformulasbeing

used(intheneighboringgraycells).Forinstance,theweeks

arecalculatedusingthefollowingformula(insteadofINT,you

canuseFLOORtorounddowntoaprecisedate—thelevelof

precisionisindicatedbythesecondparameter):

=FLOOR(days/52.18,.01)



Hereisamuchmorereadablerepresentationofthetime

youspentonvarioustasks





Creatinganewrangename



Simultaneouslyshowingthetotaltimeindifferent

formats



Hack24.:ShowtheWeekdayorMonth

ofaDate

Togetfromadatevaluetotheactualnameoftheday—

inspiredbythehack"ReturntheWeekdayofaDate"from

DavidandRainaHawley'sExcelHacks,2ndEdition—youneed

topressacoupleofdifferentfunctionsintoservice.

AmongGoogleSpreadsheet'sfunctionsareafewthatletyou

getthenameofthedayormonthforagivendatevalue.Takea

lookatthesamplespreadsheetwithuserregistrationdates

showninFigure3-20.Totheleftside,youcanseealistof

usernames;nexttothem,youcanseethedateonwhicheach

userregisteredfortheservice.Datesareeasyenoughtoget

intoaspreadsheet,buttogetthespreadsheettoprintoutthe

weekdayineveryrow,you'llneedtousesomefunctions.The

functionsyouneedtopicktheweekdayarecalledWEEKDAY

andCHOOSE.TheWEEKDAYfunctionreturnsanumberfrom1

to7,where1isSunday,2isMonday,3isTuesdayandsoon.



NOTE

Wonderinghowtocalculatethenumberofdaysthe

userhasbeenregisteredsofar?Checkout[Hack#25]

forcompletedetails.

Tryitoutyourselfbyenteringthefollowingintoanycell:

=WEEKDAY(B2)

ThisformulashowsthatApril21,2004(thevalueinB2),isa

"4",whichmeansWednesday.(AquickjumpovertoGoogle

Calendarathttp://calendar.google.comverifiesthis.)Butthat

isn'tveryreadable—youstillneedtoconvertthisnumberinto

thenameoftheweekday.Todothis,usetheCHOOSEfunction,

whichtakesanindexvalueasfirstparameter,andthendecides

onanyofthefollowingparametervaluesprovidedbasedon



thatindex.Thisbecomesclearwhenyoulookattheformula

necessarytoreturntheverboseweekday:

CodeView:



=CHOOSE(WEEKDAY(B2),"Sunday","Monday","Tuesday","Wednesday"

"Friday","Saturday")

























Ifthefirstparameteris1,thefunctionwillchoose"Sunday";if

it's2,itwillchoose"Monday,"andsoon.Putthisformulainto

the"Weekdayregistered"fieldineachcolumn,anditwill

correctlydisplaythedaynamesasshowninFigure3-20.Andif

youprefertheweekdaytobeshowninabbreviatedform,like

"Sun,""Mon,"and"Tue,"youcanwrapthiswholeformulain

theLEFTfunction,whichtakestwoparameters(atextstring

andthenumberofletterstoprint):

AuserregistrationdatestableinGoogleSpreadsheets



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Hack 23. Show Elapsed Time as Days and Hours

Tải bản đầy đủ ngay(0 tr)

×