7 Ways To Get The Weekday Name From A Date In Excel
文章推薦指數: 80 %
Format a Date as the Weekday Name · Select the dates which we want to convert into weekday names. · Go to the Home tab and click on the small launch icon in the ... 7WaysToGetTheWeekdayNameFromADateInExcelWhatdayoftheweekis2019-11-14?IsitaMonday,Tuesday,Wednesday,etc…It’sprettycommontowanttoknowwhatdayoftheweekagivendatefallsonandunlessyou’vegotsomesortofgiftforknowingthat,you’regoingtoneedawaytofigureitout.DownloadExampleFilesInExcel,therearemanydifferentwaystodeterminethis. Inthispost,we’regoingtoexplore7waystoachievethistask.TableofContents FormataDateastheWeekdayNameGettheWeekdayNamewiththeTEXTFunctionGettheWeekdayNumberwiththeWEEKDAYFunctionGettheWEEKDAYNameUsingPowerQueryGettheWEEKDAYNameinaPivotTablewiththeWEEKDAYDAXFunctionGettheWeekdayNameinaPivotTablewiththeFORMATDAXFunctionGettheWeekdayNamewithaPowerPivotCalculatedColumnConclusionsFormataDateastheWeekdayNameThefirstoptionwe’regoingtolookatinvolvesformattingourdatecells.DatesinExcelarereallyjustserialnumbersstartingat1forthedate1900-01-01.Formattingiswhatmakesthedatelooklikeadate.Therearemanywaystoformattheseserialnumberstodisplaythedateinvariousformatslikeyyyy-mm-dd,dd/mm/yyyy,dd-mmm-yyetc…Oneofthepossibleformattingoptionsfortheseserialnumbersistodisplaytheweekdaynamewithacustomddddordddformat.WecanformatourdatesfromtheFormatCellsdialogbox.Selectthedateswhichwewanttoconvertintoweekdaynames.GototheHometabandclickonthesmalllaunchiconinthelowerrightcorneroftheNumbersection.ThiswillopenuptheFormatCellsdialogbox.WecanalsoopenuptheFormatCellsdialogafewotherways.ThekeyboardshortcutCtrl+1.Rightclickontheselectedcells➜chooseFormatCellsfromthemenu.GototheNumbertabintheFormatCellsdialogbox.SelectCustomastheCategory.AddddddintotheTypefieldforthefullweekdaynameordddfortheabbreviatedweekdayname.PresstheOKbutton.Nowourdateswillappearastheweekdaynamesintheworksheet.Thedatesarestillinsidethecellsandcanbeseenintheformulabarwhenacellisselected.GettheWeekdayNamewiththeTEXTFunctionTheTEXTfunctionwillallowustoconvertnumberstotextandapplyformattingtothosenumbers.=TEXT(1234,"$#,###")WecanusetheTEXTfunctiontoconvertthenumber1234intothetextstring$1,234withtheaboveformula.Sincedatesarereallyjustserialnumbers,wecanusethisfunctiontoconvertanydateintoatextstringwiththeweekdaynameformat.TEXTSyntax=TEXT(Value,Format)Value (required)isthevaluetoconverttoatextstring.Format(required) istheformattingtoapplywhenconvertingtoatextstring.=TEXT(B2,"dddd")TheaboveformulawillconvertourdatevalueincellB2intothecorrespondingweekdayname.InthisexamplewegetavalueofFridayfromthedate2020-09-18.GettheWeekdayNumberwiththeWEEKDAYFunctionWhiletheresultsaren’tquiteasuseful,thereisalsoaWEEKDAYfunctioninExcel.Thiswillconvertadateintoacorrespondingnumberbetween1and7representingtheweekday.WEEKDAYSyntax=WEEKDAY(Date,[Type])Date(required)thedatetofindtheweekdaynumberfrom.Type(optional)theweekdaynumbertypetoreturn.Omittedor1returns1forSundaythrough7forSaturday.2returns1forMondaythrough7forSunday.3returns0forMondaythrough6forSunday.11returns1forMondaythrough7forSunday.12returns1forTuesdaythrough7forMonday.13returns1forWednesdaythrough7forTuesday.14returns1forThursdaythrough7forWednesday.15returns1forFridaythrough7forThursday.16returns1forSaturdaythrough7forFriday.17returns1forSundaythrough7forSaturday.=WEEKDAY(B2,1)TheaboveformulawillconvertourdatevalueincellB2intothecorrespondingweekdaynumber.Thesecondargumentvalueof1willreturna1forSundaythroughto7foraSaturday.Inthiscase2019-09-18returnsa6becauseit’saFriday.CombiningSWITCHwithWEEKDAYtoReturntheWeekdayNameOnitsown,theWEEKDAYfunctioncanonlyreturnanumberrepresentingtheweekday,butwecancombineitwiththeSWITCHfunctiontogettheweekdayname.=SWITCH(WEEKDAY(B2,1), 1,"Sun", 2,"Mon", 3,"Tue", 4,"Wed", 5,"Thu", 6,"Fri", 7,"Sat")TheWEEKDAYfunctionreturnsanumberfrom1to7andwecanthenusetheSWITCHfunctiontoassignaweekdaynametoeachofthesenumbers.GettheWEEKDAYNameUsingPowerQueryPowerQuery(alsoknownasGet&Transform)isapowerfuldatawranglingtoolavailableinExcel2016onward.Itmakesanydatatransformationeasyanditcangetthenameoftheweekdaytoo.Wefirstneedtoimportourdataintothepowerqueryeditor.WeneedourdatainsideanExceltable.SelectacellinsidetheExceltablecontainingthedates.GototheDatatabintheribbon.PresstheFromTable/RangecommandintheGet&TransformDatasection.Thiswillopenupthepowerqueryeditor.Wecannowtransformourdatesintothenameoftheweekday.Weneedtomakesurethecolumnisconvertedtothedatedatatype.ClickontheiconintheleftofthecolumnheadingandselectDatefromtheoptions.Withthedatecolumnselected,gototheAddColumntab.SelectDate ➜Day ➜NameofDay.=Table.AddColumn(#"ChangedType","DayName",eachDate.DayOfWeekName([Date]),typetext)ThiswilladdanewcolumncontainingtheweekdaynameandwecanseetheMcode that’sgeneratedinthepowerqueryformulabar.Thisusesthe Date.DayOfWeekNamepowerqueryfunction.AsimilarcommandcanbefoundintheTransformtab.Thedifferenceis,thiswillnotaddanewcolumn,butrathertransformtheselectedcolumn.GettheWEEKDAYNameinaPivotTablewiththeWEEKDAYDAXFunctionDidyouknowyoucansummarizetextvalueswithapivottable?Well,wecangoastepfurtherandsummarizeourdatesasalistofweekdaynamesinsideourpivottableusingaDAXmeasure!Weneedtocreateapivottablefromourdata.Selectacellinsidethedata.GototheInserttabintheribbon.PressthePivotTablecommand.IntheCreatePivotTablemenuchecktheoptiontoAddthisdatatotheDataModelandpresstheOKbutton.Thiswillcreateanewblankpivottableintheworkbookandaddthedataintothedatamodel.AddingthedatatothedatamodelwillallowustousetheDAXformulalanguagewithourpivottable.Nowwecancreateameasuretoconvertourdatesintonamesandsummarizetheresultsintoacommaseparatedlist.Selectacellinsidethepivottable.RightclickonthetableinthePivotTableFieldswindowandselectAddMeasurefromthemenuoptions.ThiswillopenuptheDAXformulaeditorandwecancreateourDAXmeasure.WecannowaddthefollowingformulaintotheDAXformulaeditor.=CONCATENATEX( Activities, SWITCH( WEEKDAY(Activities[Date],1), 1,"Sun", 2,"Mon", 3,"Tue", 4,"Wed", 5,"Thu", 6,"Fri", 7,"Sat" ), "," )GiveournewmeasureanamelikeNameofDays.AddtheaboveDAXformulaintotheformulabox.ToseetheresultsofourDAXformula,allweneedtodoisadditintotheValuesareaofourPivotTableFieldswindow.ThisisverysimilartotheWEEKDAYfunctionsolutionwithExcelfunctions.TheonlydifferenceisweneedtoaggregatetheresultswithaCONCATENATEXfunctiontodisplayinsideourpivottable.GettheWeekdayNameinaPivotTablewiththeFORMATDAXFunctionAnotherDAXfunctionwecanusetogettheweekdaynameistheFORMATfunction.ThisisverysimilartoExcel’sTEXTfunctionandwillallowustoapplyacustomformattoourdatevalues.=CONCATENATEX(Activities,FORMAT(Activities[Date],"dddd"),",")TheprocessistheexactsameasthepreviousDAXexample,butinsteadwecreateameasurewiththeaboveformula.GettheWeekdayNamewithaPowerPivotCalculatedColumnIfyouhavethepowerpivotadd-inforExcel,thenyoucanuseDAXtocreateacalculatedcolumninthedatamodel.Ifourdataisn’talreadyinthedatamodel,wecaneasilyadditbygoingtothePowerPivottabintheribbon ➜selectingAddtoDataModel.Nowwecanopenupthepowerpivotwindowbygoingtothe PowerPivottab ➜selectingManageDataModel.=FORMAT(Activities[Date],"dddd")Insidethepowerpivotwindow,wecanaddournewcalculatedcolumn.DoubleclickontheAddColumnheadingandgivethenewcolumnanamelikeWeekday.SelectacellinsidethenewcolumnandaddtheaboveDAXformulaintotheformulabarandpressenter.Whenweclosethepowerpivotwindow,wenowhavethenewWeekdayfieldavailabletouseinourpivottableandwecanadditintotheRows,ColumnsorFilterarea ofthepivottable.ConclusionsTherearelotsofoptionstogetthenameofthedayfromadateinExcel.Wecoveredformatting,Excelformulas,powerqueryandDAXformulasinthedatamodel.Thereareprobablyafewmorewaysaswell.LetmeknowinthecommentsifImissedyourfavouritemethod.AbouttheAuthorJohnMacDougallJohnisaMicrosoftMVPandfreelanceconsultantandtrainerspecializinginExcel,PowerBI,PowerAutomate,PowerAppsandSharePoint.YoucanfindotherinterestingarticlesfromJohnonhisblogorYouTubechannel.SubscribeRelatedPosts BrowseAll7WaystoRenameaSheetinMicrosoftExcelSep25,2021Keepingyourspreadsheetorganizedisimportant!Awellorganizedspreadsheet...readmore8WaystoMergeCellsinMicrosoftExcelSep8,2021Mergedcellsareoneofthemostpopularoptionsusedbybeginnerspreadsheet...readmore6WaystoCountColoredCellsinMicrosoftExcel[IllustratedGuide]Sep7,2021YouhaveprobablyusedcolorcodinginyourExceldataorseenitina...readmoreComments3Comments Meni on2019-11-20at14:42 HiJohn, here’sanothermethodtogettheweekdayname,usingtheCHOOSEfunctioncombinedwithWEEKDAY:=CHOOSE(WEEKDAY(TODAY()),”Sun”,”Mon”,”Tue”,”Wed”,”Thu”,”Fri”,”Sat”)Ofcourse,TODAY()canbereplacedbyanyvaliddate.BestRegards, MeniPorat John on2019-11-20at15:36 Yes,CHOOSEisanothergoodoption. MeniPorat on2019-11-23at02:30 TalkingabouttheWEEKDAY,itiswell-knownthatthisfunctionhastwo“bugs”andone“flaw”:The“bugs”: 1) itdoesnotreturnthecorrectdayofweekifthedateisbetween1900/1/1and1900/2/28. 2) itconsiders1900/2/29asavaliddate(whichiswrong:1900wasnotaleapyear)Theflaw: itcan’tcalculateweekdaysbefore1/1/1900. Inaddition,WEEKDAYreturnsanumber,whichmustbefurthertranslatedintoaname(whichyourpostimpressivelydoes…) Thereareseveralsolutionstotheabove-mentionedproblems.Youarekindlyinvitedtovisitmyblogandseemysolution:https://meniporat.blogspot.com/2012/07/excel-calculating-weekday-for-given-date_2236.htmlBestRegards, MeniPoratGettheLatestMicrosoftExcelTips FollowUsFollowusonsocialmediatostayuptodatewiththelatestinMicrosoftExcel!FollowFollowFollowFollow
延伸文章資訊
- 1[Excel教學]如何使用WEEKDAY函數和CHOOSE函數來轉換 ...
必須使用DATE 函數輸入日期,或是使用結果為日期的其他公式或函數。例如,使用DATE(2008,5,23) 表示2008 年5 月23 日。若使用文字格式輸入日期,可能會 ...
- 2WEEKDAY Function - Formula, Examples, How to Use Weekday
The WEEKDAY Function is an Excel DATE and TIME Function. ... in any format of our choice, we can ...
- 3How to convert date to weekday, month, year name or number ...
Convert a date to weekday/month name with CHOOSE function
- 4How to use the Excel WEEKDAY function | Exceljet
Summary. The Excel WEEKDAY function takes a date and returns a number between 1-7 representing th...
- 5WEEKDAY 函數
WEEKDAY 函數語法具有下列引數:. Serial_number 必要。 這是代表要尋找之該天日期的序列值。 日期必須使用DATE 函數輸入,或為其他公式或函數的結果。