Date Headers

Date headers contains an RFC 2822 formatted date (i.e. what PHP's date('r') returns). They are used anywhere a date or time is needed to be presented as a message header.

The data on which a date header is modeled is simply a UNIX timestamp such as that returned by time() or strtotime(). The timestamp is used to create a correctly structured RFC 2822 formatted date such as Tue, 17 Feb 2009 22:26:31 +1100.

The obvious place this header type is used is in the Date: header of the message itself.

It's easy to add a new date header to a HeaderSet. You do this by calling the HeaderSet's addDateHeader() method.

<?php

$message = Swift_Message::newInstance();

$headers = $message->getHeaders();

$headers->addDateHeader('Your-Header-Name', strtotime('3 days ago'));

Changing the value of an existing date header is done by calling it's setTimestamp() method.

<?php

$date = $message->getHeaders()->getHeader('Date');

$date->setTimestamp(time());

When output via toString(), a date header produces something like the following:

<?php

$date = $message->getHeaders()->getHeader('Date');

echo $date->toString();

/*

Date: Wed, 18 Feb 2009 13:35:02 +1100

*/

NOTE: Documentation for version 3 is in the wiki.