excel vba - How to get the Day Name of Date? - Stack Overflow

文章推薦指數: 80 %
投票人數:10人

If you want the weekday for any date in any regional settings sDayName = Format(DateSerial(2016, 11, 4), "dddd") 'change 2016, 11, ... Home Public Questions Tags Users Collectives ExploreCollectives FindaJob Jobs Companies Teams StackOverflowforTeams –Collaborateandshareknowledgewithaprivategroup. CreateafreeTeam WhatisTeams? Teams CreatefreeTeam CollectivesonStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore excelvba-HowtogettheDayNameofDate? AskQuestion Asked 5years,1monthago Active 4years,4monthsago Viewed 52ktimes 3 1 IhaveasmallcodethatgetstheDayNameoftheDateslistedinExcel.Buttheproblemis,it'snotgettingtherightDayName(e.g.Tuesday). ForExample: sDayName=Format(Day(11/1/2016),"dddd") ThentheoutputproducesanincorrectDayNamewhichis: sDayName="Sunday" whenit'ssupposedtobe"Tuesday". Thanksforthehelpguys. vbaexceldatedate-formatting Share Improvethisquestion Follow askedNov3'16at18:28 bigbryanbigbryan 35166goldbadges1616silverbadges3232bronzebadges 5 3 haveyoutriedsDayName=Format("11/01/2016","dddd")?? – cyberponk Nov3'16at18:31 1 RemovetheDay()portion,it'snotneeded – tigeravatar Nov3'16at18:33 1 CheckonlinedocumentationforFormat()functionwhereyoushouldfindfirstdayoftheweekparameter – user3598756 Nov3'16at18:35 @cyberponkThanksMan.Problemsolved.PleasepostyouranswersoIcanmarkitascorrect. – bigbryan Nov3'16at18:36 1 FWIW-YourcodewastryingtofindtheDayof5.45634920634921E-03,i.e.11dividedby1,dividedby2016.As5.45634920634921E-03isequivalenttoadate/timeof7:51amon30Dec1899,theDayis30.Formatting30usinga"dddd"formatfirstworksoutthatadateof30represents29Jan1900,whichisaMonday.But,duetothebuginExcelwhichcausesittothinkthat1900wasaleapyear,thisgetsreportedbyExcelasSunday. – YowE3K Nov3'16at19:43 Addacomment  |  2Answers 2 Active Oldest Votes 10 Foryourspecificrequest,assumingyourdatestringisformattedasyourregionalsetings: sDayName=Format("11/01/2016","dddd") Ifyouwanttheweekdayfortoday: sDayName=Format(Date,"dddd") Ifyouwanttheweekdayforanydateinanyregionalsettings sDayName=Format(DateSerial(2016,11,4),"dddd") 'change2016,11,4foryouryear,month,dayvalues :) Share Improvethisanswer Follow editedJul17'17at16:37 answeredNov3'16at18:36 cyberponkcyberponk 1,2631414silverbadges1818bronzebadges 1 PassingaStringthatrepresentsaDatetoFormatisrarelyagoodidea. – Comintern Nov3'16at19:19 Addacomment  |  4 WEEKDAYFunctioncanbeusedonthistopicandinVbaCodes.Forexample: Label2.Caption=WeekdayName(Weekday(TextBox2,0),False,0) IusedthisfunctioninwhenIcreateduserformaboutdateentrytoactivecell. Share Improvethisanswer Follow editedApr7'17at9:06 MartijnPieters♦ 929k256256goldbadges36823682silverbadges31083108bronzebadges answeredNov29'16at17:56 kadrleynkadrleyn 14155bronzebadges Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedvbaexceldatedate-formattingoraskyourownquestion. TheOverflowBlog Smashingbugstosetaworldrecord:AWSBugBust Podcast399:ZerotoMVPwithoutprovisioningadatabase FeaturedonMeta Reducingtheweightofourfooter NewresponsiveActivitypage Communityinputneeded:Therulesforcollectivesarticles A/BtestingontheAskpage Visitchat Linked 0 UsingexcelVBA,Isthereawayformetogetthenameofthecurrentdatesday(eg.Monday) 0 ExcelVBA-Isthereawaytogetthedateinthecurrentweek,givenonlythedayname? Related 759 Howtogetthelastdayofthemonth? 1986 HowtoreturnonlytheDatefromaSQLServerDateTimedatatype 2049 HowdoIcreateanExcel(.XLSand.XLSX)fileinC#withoutinstallingMicrosoftOffice? 954 Howtosubtractadayfromadate? 2699 HowdoIgetthecurrentdateinJavaScript? 854 GetmonthnamefromDate 2893 HowtoformataJavaScriptdate 1211 HowtogetcurrenttimeanddateinAndroid 1253 GetthecurrentyearinJavaScript 770 HowdoIgetthedayofweekgivenadate? HotNetworkQuestions Isthisaswitch? FillingGridPointsIntersectedbyaCircle Changingchordsinjazz IstheargumentthatGodcan'tbeomnipotent,omniscientandallgoodinvalidbecauseomnipotencewouldletGodviolatelogic Isthereanysortofnaturalmechanismthatwouldexplainwhymygiantsaretallerorshorterdependingonhowmanyhornstheyhave? Usingecho""tocreateanewemptyfileisn'tcreatinganemptyfile A(probably)shortfictionwhereaBabylonianpotter’swheelturnedouttobetheearliestcylinderphonograph WhydoesTritonesoundgoodinLydianscale? Coloringtheareabetweencircleandpathintikz Issoundaclassicalmechanicphenomenonorisitaquantumeffect? Howtogetarangedbonusactionattackbefore/withoutattackingorusingacombatmanoeuvre? WilltherebeafiveplanetconjunctioninMarch,2022? Afterourfirstzoominterview,mypotentialsupervisoraskedmetoprepareapresentationforanextzoommeeting 15ACircuitbreakerkeepstrippingonthreePCs EventDispatchingSystem AoCG2021Day9:Spiralmemorystresstest Howrealisticisaceilingcrawl/cling,canitactuallybedone? Howtofixoverlysensitiveswitch WhyisRK45usedasthe"default"methodfornon-stiffODEsratherthanamultistepone? Alternatewordfor"veryinaccurateplan" Can'tuninstallEdge Isitcorrectandnaturaltosay"I'llmeetyouat$100"meaningI'llaccept$100forsomething? GetdatafromnfofilewithfunctionsPython Whatistheratiooffattoflourinshortcrustpastry? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-vb Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?