summaryrefslogtreecommitdiffstats
path: root/helpcontent2/source/text/sbasic/shared/03030102.xhp
blob: aea6339a0ce0329f4336c776827528017f8c672b (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
<?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="textsbasicshared03030102xml" indexer="include" status="PUBLISH">
  <title id="tit" xml-lang="en-US">DateValue Function</title>
  <filename>/text/sbasic/shared/03030102.xhp</filename>
</topic>
<history>
<created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created>
</history>
</meta>
<body>

<section id="datevalue">
  <bookmark xml-lang="en-US" branch="index" id="bm_id3156344"><bookmark_value>DateValue function</bookmark_value>
  </bookmark>
  <h1 id="hd_id3156344"><variable id="DateValue_H1"><link href="text/sbasic/shared/03030102.xhp" name="DateValue Function">DateValue Function</link></variable></h1>
  <paragraph role="paragraph" id="par_id3150542" xml-lang="en-US">Returns a <emph>Date</emph> object from a string representing a date.</paragraph>
  <paragraph role="paragraph" id="par_id671643046319326">The returned object is represented internally as a single numeric value corresponding to the specified date. This value can be used to calculate the number of days between two dates.</paragraph>
</section>

<embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
<bascode>
  <paragraph role="bascode" id="par_id3154910" xml-lang="en-US">DateValue(date As String)</paragraph>
</bascode>
<embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
<section id="parm1">
  <paragraph role="paragraph" id="par_id3153770"><emph>date</emph>: A string that contains the date that will be converted to a <emph>Date</emph> object.</paragraph>
  <note id="par_id841643046880968">The string passed to <literal>DateValue</literal> must be expressed in one of the date formats defined by your locale setting (see <switchinline select="sys"><caseinline select="MAC"><menuitem>%PRODUCTNAME - Preferences</menuitem></caseinline><defaultinline><menuitem>Tools - Options</menuitem></defaultinline></switchinline><menuitem> - Language Settings - Languages</menuitem>) or using the ISO date format "yyyy-mm-dd" (year, month and day separated by hyphens).</note>
</section>
<embed href="text/sbasic/shared/00000003.xhp#functvalue"/>
<paragraph role="paragraph" localize="false" id="par_id3153194">Date.</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"/>
<bascode>
  <paragraph role="bascode" localize="false" id="par_id3155412">Sub ExampleDateValue</paragraph>
  <paragraph role="bascode" localize="false" id="bas_id671643047301348">    Dim aDate As Date</paragraph>
  <paragraph role="bascode" localize="false" id="bas_id291643047301592">    aDate = DateValue("2021-12-20")</paragraph>
  <paragraph role="bascode" id="bas_id461643047301827">    ' Prints the localized date</paragraph>
  <paragraph role="bascode" localize="false" id="bas_id551643047302107">    MsgBox aDate</paragraph>
  <paragraph role="bascode" id="bas_id616430473023063">    ' Extracts the year, month and day from the date object</paragraph>
  <paragraph role="bascode" localize="false" id="bas_id281643047302645">    MsgBox Year(aDate)</paragraph>
  <paragraph role="bascode" localize="false" id="bas_id391643047302940">    MsgBox Month(aDate)</paragraph>
  <paragraph role="bascode" localize="false" id="bas_id201643047303163">    MsgBox Day(aDate)</paragraph>
  <paragraph role="bascode" id="bas_id601643047303420">    ' Prints the numeric value corresponding to the date (as Long type)</paragraph>
  <paragraph role="bascode" localize="false" id="bas_id381643047303644">    MsgBox CLng(aDate)</paragraph>
  <paragraph role="bascode" localize="false" id="par_id3149262">End Sub</paragraph>
</bascode>

  <section id="relatedtopics">
    <embed href="text/sbasic/shared/03030101.xhp#DateSerial_H1"/>
  </section>
</body>
</helpdocument>