blob: 01ed090735da48404e5a8998a9e77cd8068dd01e (
plain)
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
|
<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
<!--
* 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 .
-->
<meta>
<topic id="textsbasicshared03150000xml" indexer="include" status="PUBLISH">
<title id="tit" xml-lang="en-US">FormatDateTime Function [VBA]</title>
<filename>/text/sbasic/shared/03150000.xhp</filename>
</topic>
</meta>
<body>
<section id="FormatDateTime">
<bookmark xml-lang="en-US" branch="index" id="bm_id3150499">
<bookmark_value>FormatDateTime function</bookmark_value>
</bookmark>
<paragraph id="hd_id3150499" role="heading" level="1" xml-lang="en-US"><link href="text/sbasic/shared/03150000.xhp" name="FormatDateTime Function [VBA]">FormatDateTime Function [VBA]</link></paragraph>
<paragraph id="par_id3151384" role="paragraph" xml-lang="en-US">Applies a date and/or time format to a date expression and returns the result as a string.</paragraph>
</section>
<embed href="text/sbasic/shared/00000003.xhp#vbasupport"/>
<embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
<bascode>
<paragraph id="par_id3143267" role="bascode" localize="false" xml-lang="en-US">FormatDateTime (DateExpression as Date [, NamedFormat as Integer])</paragraph>
</bascode>
<embed href="text/sbasic/shared/00000003.xhp#functvalue"/>
<paragraph id="par_id3150669" role="paragraph" localize="false" xml-lang="en-US">String</paragraph>
<embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
<paragraph id="par_id240720170117391741" role="paragraph" xml-lang="en-US"><emph>DateExpression</emph>: The date expression to be formatted.</paragraph>
<paragraph id="par_id24072017011739895" role="paragraph" xml-lang="en-US"><emph>NamedFormat</emph>: An optional <emph>vbDateTimeFormat</emph> enumeration specifying the format that is to be applied to the date and time expression. If omitted, the value <emph>vbGeneralDate</emph> is used.</paragraph>
<paragraph role="heading" id="hd_id811512136434300" level="3" xml-lang="en-US">Date and Time formats (vbDateTimeFormat enumeration)</paragraph>
<section id="FormatDateTime_constants">
<table id="tab_0001">
<tablerow>
<tablecell>
<paragraph role="tablehead" id="par_id201512137337536" xml-lang="en-US">Named Constant</paragraph>
</tablecell>
<tablecell>
<paragraph role="tablehead" id="par_id481512137342798" xml-lang="en-US">Value</paragraph>
</tablecell>
<tablecell>
<paragraph role="tablehead" id="par_id781512137345583" xml-lang="en-US">Description</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph role="tablecontents" id="par_id121512137348477" xml-lang="en-US" localize="false">vbGeneralDate</paragraph>
</tablecell>
<tablecell>
<paragraph role="tablecontents" id="par_id511512137351182" xml-lang="en-US" localize="false">0</paragraph>
</tablecell>
<tablecell>
<paragraph role="tablecontents" id="par_id991512137353869" xml-lang="en-US">Displays a date and/or time as defined in your system's General Date setting. If a date only, no time is displayed; If a time only, no date is displayed.</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph id="par_id181512137579110" role="tablecontents" xml-lang="en-US" localize="false">vbLongDate</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id651512137595327" role="tablecontents" xml-lang="en-US" localize="false">1</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id841512137597989" role="tablecontents" xml-lang="en-US" >Display a date using the long date format specified in your computer's regional settings.</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph role="tablecontents" id="par_id391512138077008" xml-lang="en-US" localize="false">vbShortDate</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id651512137594327" role="tablecontents" xml-lang="en-US" localize="false">2</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id841512137397989" role="tablecontents" xml-lang="en-US" >Display a date using the short date format specified in your computer's regional settings.</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph id="par_id181512137679110" role="tablecontents" xml-lang="en-US" localize="false">vbLongTime</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id651512137595227" role="tablecontents" xml-lang="en-US" localize="false">3</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id841512147597989" role="tablecontents" xml-lang="en-US" >Displays a time as defined in your system's Long Time settings.</paragraph>
</tablecell>
</tablerow>
<tablerow>
<tablecell>
<paragraph id="par_id183512137579110" role="tablecontents" xml-lang="en-US" localize="false">vbShortTime</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id651512937595327" role="tablecontents" xml-lang="en-US" localize="false">4</paragraph>
</tablecell>
<tablecell>
<paragraph id="par_id841517137597989" role="tablecontents" xml-lang="en-US" >Display a time using the 24-hour format (hh:mm).</paragraph>
</tablecell>
</tablerow>
</table>
</section>
<embed href="text/sbasic/shared/00000003.xhp#errorcode"/>
<embed href="text/sbasic/shared/00000003.xhp#err13"/>
<embed href="text/sbasic/shared/00000003.xhp#functexample"/>
<bascode>
<paragraph role="bascode" id="par_id851512148348809" xml-lang="en-US" localize="false">REM ***** BASIC *****</paragraph>
<paragraph role="bascode" id="par_id981512148374491" xml-lang="en-US" localize="false">Option VBASupport 1</paragraph>
<paragraph role="bascode" id="par_id541512148389055" xml-lang="en-US" localize="false">Sub DateFormat</paragraph>
<paragraph role="bascode" id="par_id91512148403780" xml-lang="en-US" localize="false"> Dim d as Date</paragraph>
<paragraph role="bascode" id="par_id551512148424467" xml-lang="en-US" localize="false"> d = ("1958-01-29 00:25")</paragraph>
<paragraph role="bascode" id="par_id541512148446032" xml-lang="en-US"> msgbox("General date format : " & FormatDateTime(d))</paragraph>
<paragraph role="bascode" id="par_id71512148472413" xml-lang="en-US" > msgbox("Long date format : " & FormatDateTime(d,vbLongDate))</paragraph>
<paragraph role="bascode" id="par_id561512148491949" xml-lang="en-US" > msgbox("Short date format : " & FormatDateTime(d,vbShortDate))</paragraph>
<paragraph role="bascode" id="par_id521512148501199" xml-lang="en-US" > msgbox("Long time format : " & FormatDateTime(d,3))</paragraph>
<paragraph role="bascode" id="par_id521512148513930" xml-lang="en-US" > msgbox("Short time format : " & FormatDateTime(d,vbShortTime))</paragraph>
<paragraph role="bascode" id="par_id211512148529064" xml-lang="en-US" localize="false">End Sub</paragraph>
</bascode>
<section id="relatedtopics">
<embed href="text/sbasic/shared/00000003.xhp#VBATimeAndDate"/>
</section>
</body>
</helpdocument>
|