# xs:gYearMonth

Converts $string-var (a string in the gYearMonth format) to the gYearMonth data type.

If the value of $string-var is the empty sequence, the empty sequence is returned.The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

If the value of $string-var is not valid to the gYearMonth format, the following error is reported:

Could not cast "invalid_gYearMonth_string" to type [gYearMonth@htttp://www.w3.org/2001/XMLSchema] is displayed.

Where invalid_gYearMonth_string is the string not valid to the time format, for example: "2003-8".

### Signatures

xs:gYearMonth(xs:string $string-var) —> xs:gYearMonth

### Arguments

Data Type | Argument | Description
--- | --- | ---
xs:string | $string-var | Represents a string with the month and year specified with one of the following formats: YYYY-MM YYYY-MM Z YYYY-MM+hh:mm YYYY-MM-hh:mm
|  | YYYY | Year.
- | Separator between year and months.
MM | Month (as a number).
+ | Positive time zone offset. This option is optional. If a plus or minus is not specified, + is assumed.
- | Negative time zone offset. (Optional)
hh | Number of hours that the time zone differs from UTC.
mm | Number of minutes that the time zone differs from UTC.
Z | Indicates that the time corresponds to the UTC time zone.

### Returns

Returns the specified month and year in the gYearMonth data type.

### Examples

#### Simple

Invoking gYearMonth("2003-08") returns a gYearMonth value corresponding to August 2003, as shown in the following example query:

    <result>{xs:gYearMonth("2003-08")}</result>

The preceding query, generates the following XML result:

    <result>2003-08</result>

#### UTC Time Zone

Invoking gYearMonth("2003-08Z") returns a gYearMonth value corresponding to August 2003 in the UTC time zone, as shown in the following example query:

    <result>{xs:gYearMonth("2003-08Z")}</result>

The preceding query, generates the following XML result:

    <result>2003-08Z</result>

#### Error—Incorrect Format

Invoking gYearMonth("2003-8") outputs an error because the month is not specified using two digits.

For example, the following example query:

    <result>{xs:gYearMonth("2003-8")}</result>

Produces the following error:

    Error occurred while executing XQuery: Could not cast "2003-8" to type [gYearMonth@http://www.w3.org/2001/XMLSchema]

Related Topics

W3C gYearMonth data type description