No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Rechercher une fonction PHP

DateTime::setDate

date_date_set

(PHP 5 >= 5.2.0, PHP 7)

DateTime::setDate -- date_date_setSets the date

PHP: DateTime::setDate - Manual Home of Manuel PHP  Contents Haut

Description

Object oriented style

public DateTime::setDate ( int $year , int $month , int $day ) : DateTime

Procedural style

date_date_set ( DateTime $object , int $year , int $month , int $day ) : DateTime

Resets the current date of the DateTime object to a different date.

PHP: DateTime::setDate - Manual Home of Manuel PHP  Contents Haut

Parameters

object

Procedural style only: A DateTime object returned by date_create(). The function modifies this object.

year

Year of the date.

month

Month of the date.

day

Day of the date.

PHP: DateTime::setDate - Manual Home of Manuel PHP  Contents Haut

Return Values

Returns the DateTime object for method chaining or FALSE on failure.

PHP: DateTime::setDate - Manual Home of Manuel PHP  Contents Haut

Changelog

Version Description
5.3.0Changed the return value on success from NULL to DateTime.

PHP: DateTime::setDate - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 DateTime::setDate() example

Object oriented style

<?php
$date 
= new DateTime();
$date->setDate(200123);
echo 
$date->format('Y-m-d');
?>

Procedural style

<?php
$date 
date_create();
date_date_set($date200123);
echo 
date_format($date'Y-m-d');
?>

The above examples will output:

2001-02-03

Example #2 Values exceeding ranges are added to their parent values

<?php
$date 
= new DateTime();

$date->setDate(2001228);
echo 
$date->format('Y-m-d') . "\n";

$date->setDate(2001229);
echo 
$date->format('Y-m-d') . "\n";

$date->setDate(2001143);
echo 
$date->format('Y-m-d') . "\n";
?>

The above example will output:

2001-02-28
2001-03-01
2002-02-03
Find a PHP function
Error Infobrol

Can not display this page of the Infobrol website

Type of error (18-01)

Unknown format specifier "&"

Please try again in a few minutes…

Return to the home page




Steph