Cloud Spanner Client - Class Date (1.56.0)

Reference documentation and code samples for the Cloud Spanner Client class Date.

Represents a value with a data type of Date.

Example:

use Google\Cloud\Spanner\SpannerClient;

$spanner = new SpannerClient();

$date = $spanner->date(new \DateTimeImmutable('1995-02-04'));
// Date objects can be cast to strings for easy display.
echo (string) $date;

Methods

__construct

Parameter
NameDescription
value DateTimeInterface

The date value.

createFromValues

Create a Date from integer or string values.

Example:

$date = Date::createFromValues(1995, 02, 04);
Parameters
NameDescription
year int|string

The year.

month int|string

The month (as a number).

day int|string

The day of the month.

Returns
TypeDescription
Google\Cloud\Spanner\Date

get

Get the underlying \DateTimeInterface implementation.

Example:

$dateTime = $date->get();
Returns
TypeDescription
DateTimeInterface

type

Get the type.

Example:

echo $date->type();
Returns
TypeDescription
int

formatAsString

Format the value as a string.

Example:

echo $date->formatAsString();
Returns
TypeDescription
string

__toString

Format the value as a string.

Returns
TypeDescription
string

Constants

FORMAT

Value: 'Y-m-d'