1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
<?xml version="1.0" encoding="UTF-8"?>
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<helpdocument version="1.0">
<meta>
<topic id="textsbasicshared03030105xml" indexer="include" status="PUBLISH">
<title id="tit" xml-lang="en-US">WeekDay Function</title>
<filename>/text/sbasic/shared/03030105.xhp</filename>
</topic>
<history>
<created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created>
</history>
</meta>
<body>
<section id="weekday">
<bookmark xml-lang="en-US" branch="index" id="bm_id3153127">
<bookmark_value>WeekDay function</bookmark_value>
</bookmark>
<h1 id="hd_id3153127"><variable id="WeekDay_H1"><link href="text/sbasic/shared/03030105.xhp">WeekDay Function</link></variable></h1>
<paragraph role="paragraph" id="par_id3146795" xml-lang="en-US">This function returns the number corresponding to the weekday represented by a serial date number that is generated by the <literal>DateSerial</literal> or the <literal>DateValue</literal> functions.</paragraph>
</section>
<note id="par_id91620239579003">This help page describes the <literal>WeekDay</literal> function used in Basic scripts. If you are interested in the <literal>WeekDay</literal> function used in %PRODUCTNAME Calc, refer to <link href="text/scalc/01/func_weekday.xhp">this help page</link>.</note>
<embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
<bascode>
<paragraph role="bascode" id="par_id3149655" xml-lang="en-US">WeekDay (SerialDate, [FirstDayOfWeek])</paragraph>
</bascode>
<embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
<paragraph role="paragraph" id="par_id3151042" xml-lang="en-US">
<emph>SerialDate:</emph> Integer expression that contains the serial date number that is used to calculate the day of the week.</paragraph>
<paragraph role="paragraph" id="par_id351619718411921">
<emph>FirstDayOfWeek:</emph> Integer value indicating which weekday should be considered as the first day of the week. The default value is <emph>0</emph>, meaning that the system locale settings are used to determine the first day of the week.</paragraph>
<paragraph role="paragraph" id="par_id411619718769819">The parameter <emph>FirstDayOfWeek</emph> accepts values ranging from 0 to 7. The table below describes the meaning of each possible value:</paragraph>
<section id="WeekDay_constants">
<table id="tab_id191619718816238">
<tablerow>
<tablecell>
<paragraph id="par_id651619719561092" role="tablehead">Value</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id251619718816238" role="tablehead">VBA Constant</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id711619718816238" role="tablehead">Description</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph id="par_id731619718847838" role="tablecontent" localize="false">0</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id731619718847702" role="tablecontent" localize="false">vbUseSystemDayOfWeek</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id521619718818972" role="tablecontent">Use system locale settings</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph id="par_id821619719164117" role="tablecontent" localize="false">1</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id731619718847885" role="tablecontent" localize="false">vbSunday</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id581619719174897" role="tablecontent">Sunday (default)</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph id="par_id821619719164241" role="tablecontent" localize="false">2</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id731619718844633" role="tablecontent" localize="false">vbMonday</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id581619719173258" role="tablecontent">Monday</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph id="par_id821619719168871" role="tablecontent" localize="false">3</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id731619718840122" role="tablecontent" localize="false">vbTuesday</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id581619719174633" role="tablecontent">Tuesday</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph id="par_id821619719162897" role="tablecontent" localize="false">4</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id731619718843362" role="tablecontent" localize="false">vbWednesday</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id581619719173641" role="tablecontent">Wednesday</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph id="par_id821619719168022" role="tablecontent" localize="false">5</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id731619718849336" role="tablecontent" localize="false">vbThursday</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id581619719170014" role="tablecontent">Thursday</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph id="par_id821619719164776" role="tablecontent" localize="false">6</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id731619718849699" role="tablecontent" localize="false">vbFriday</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id581619719174271" role="tablecontent">Friday</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph id="par_id821619719169044" role="tablecontent" localize="false">7</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id731619718849001" role="tablecontent" localize="false">vbSaturday</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id581619719176055" role="tablecontent">Saturday</paragraph>
</tablecell>
</tablerow>
</table>
</section>
<note id="par_id451619720094202">The VBA constants listed above are only available if VBA support has been enabled. For more information, read the <link href="text/sbasic/shared/03103350.xhp">VBASupport Statement</link> help page.</note>
<embed href="text/sbasic/shared/00000003.xhp#functvalue"/>
<paragraph role="paragraph" id="par_id3154125" xml-lang="en-US">Integer</paragraph>
<embed href="text/sbasic/shared/00000003.xhp#errorcode"/>
<embed href="text/sbasic/shared/00000003.xhp#err5"/>
<embed href="text/sbasic/shared/00000003.xhp#functexample"/>
<paragraph role="paragraph" id="par_id3159254" xml-lang="en-US">The following example uses the function <literal>Now()</literal> to determine the current weekday.</paragraph>
<bascode>
<paragraph role="bascode" id="par_id3145749" localize="false">Sub ExampleWeekDay</paragraph>
<paragraph role="bascode" id="par_id3147426" localize="false"> Dim sDay As String</paragraph>
<paragraph role="bascode" id="par_id3148576"> ' Return And display the day of the week</paragraph>
<paragraph role="bascode" id="par_id3155412" localize="false"> Select Case WeekDay( Now )</paragraph>
<paragraph role="bascode" id="par_id3151117"> Case 1: sDay="Sunday"</paragraph>
<paragraph role="bascode" id="par_id3153952"> Case 2: sDay="Monday"</paragraph>
<paragraph role="bascode" id="par_id3153157"> Case 3: sDay="Tuesday"</paragraph>
<paragraph role="bascode" id="par_id3154942"> Case 4: sDay="Wednesday"</paragraph>
<paragraph role="bascode" id="par_id3155416"> Case 5: sDay="Thursday"</paragraph>
<paragraph role="bascode" id="par_id3154015"> Case 6: sDay="Friday"</paragraph>
<paragraph role="bascode" id="par_id3153707"> Case 7: sDay="Saturday"</paragraph>
<paragraph role="bascode" id="par_id3155065" localize="false"> End Select</paragraph>
<paragraph role="bascode" id="par_id3148993"> MsgBox "" + sDay,64,"Today Is"</paragraph>
<paragraph role="bascode" id="par_id3149019" localize="false">End Sub</paragraph>
</bascode>
<paragraph role="paragraph" id="par_id891619721286262">The following example illustrates the use <emph>FirstDayOfWeek</emph> parameter, assuming that Tuesday is the first day of the week.</paragraph>
<bascode>
<paragraph role="bascode" localize="false" id="bas_id71619721723893">Dim someDay As Long</paragraph>
<paragraph role="bascode" id="bas_id791619721724107">' The date January 1st 2021 was a Friday</paragraph>
<paragraph role="bascode" localize="false" id="bas_id441619721724360">someDay = DateSerial(2021, 01, 01)</paragraph>
<paragraph role="bascode" id="bas_id991619721724568">' Prints "6" assuming Sunday is the first day of the week</paragraph>
<paragraph role="bascode" localize="false" id="bas_id291619721724784">MsgBox WeekDay(someDay)</paragraph>
<paragraph role="bascode" id="bas_id31619721725024">' Prints "4" assuming Tuesday is the first day of the week</paragraph>
<paragraph role="bascode" localize="false" id="bas_id301619721725289">MsgBox WeekDay(someDay, 3)</paragraph>
</bascode>
<section id="relatedtopics">
<embed href="text/sbasic/shared/03030101.xhp#DateSerial_H1"/>
<embed href="text/sbasic/shared/03030102.xhp#DateValue_H1"/>
<embed href="text/sbasic/shared/03030203.xhp#Now_H1"/>
<embed href="text/scalc/01/func_weekday.xhp#weekday"/>
</section>
</body>
</helpdocument>
|