Share on Google+Share on Google+

PHP Set Date

Advertisement
In this example we will explain about PHP set date function.

DateTime::setDate

DateTime::setDate alias date_date_set function is used for resetting the current date of the DateTime object to a different date. It returns the modified DateTime.

Description

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

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

Parameters

object - Procedural style only: A DateTime object returned by date_create()

year - Year of the date.

month - Month of the date.

day - Day of the date.

Examples

<?php
date_default_timezone_set('India/Kolkata');

$datetime = new DateTime('2009-08-24 11:58:10');
$datetime->setDate(2009, 09, 07);

echo $datetime->format(DATE_RFC2822);

?>

Advertisements

Advertisement

Posted on: August 25, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.