PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




strtotime

Name

strtotime — Converts a string representation of a date or time to a UNIX timestamp.

Synopsis

int strtotime(timestring[, timestamp]);
string timestring: Time string to be converted
int timestamp (optional): Optional timestamp to use instead of the current time

Returns

UNIX timestamp; FALSE on failure

Description

strtotime() is capable of taking a string containing a date or time specification in a variety of nearly natural-language formats and converting it into a simple UNIX timestamp. The string given may be very naturally expressed, using a combination of digits and any of the following strings. These strings may be pluralized with an appended s if appropriate, and are not case-sensitive. These strings are not localized, and must be used in English.

Unless the timestamp parameter is given, the result will be calculated relative to the current system time. To cause the result to be calculated relative to another time, give the desired time as a UNIX timestamp as timestamp .

Month and Day Names and Abbreviations:

  • january

  • february

  • march

  • april

  • may

  • june

  • july

  • august

  • september

  • sept

  • october

  • november

  • december

  • sunday

  • monday

  • tuesday

  • tues

  • wednesday

  • wednes

  • thursday

  • thur

  • thurs

  • friday

  • saturday



Time Values and Specifiers:

  • am: the time is before noon

  • pm: the time is noon or later

  • year: one year; for example, "next year"

  • month: one month; for example, "last month"

  • fortnight: two weeks; for example, "a fortnight ago"

  • week: one week

  • day: a day

  • hour: an hour

  • minute: a minute

  • min: same as minute

  • second: a second

  • sec: same as second



Relative and Ordinal Specifiers:

  • ago: past time relative to now; such as "24 hours ago"

  • tomorrow: 24 hours later than the current date and time

  • yesterday: 24 hours earlier than the current date and time

  • today: the current date and time

  • now: the current date and time

  • last: modifier meaning "the preceding"; for example, "last tuesday"

  • this: the given time during the current day or the next occurrence of the given time; for example, "this 7am" gives the timestamp for 07:00 on the current day, while "this week" gives the timestamp for one week from the current time

  • next: modifier meaning the current time value of the subject plus one; for example, "next hour"

  • first: ordinal modifier, esp. for months; for example, "May first" (actually, it's just the same asnext)

  • third: see first (note that there is no "second" for ordinality, since that would conflict with thesecond time value)

  • fourth: see first

  • fifth: see first

  • sixth: see first

  • seventh: see first

  • eighth: see first

  • ninth: see first

  • tenth: see first

  • eleventh: see first

  • twelfth: see first



Time Zones:

  • gmt: Greenwich Mean Time

  • ut: Coordinated Universal Time

  • utc: same as ut

  • wet: Western European Time

  • bst: British Summer Time

  • wat: West Africa Time

  • at: Azores Time

  • ast: Atlantic Standard Time

  • adt: Atlantic Daylight Time

  • est: Eastern Standard Time

  • edt: Eastern Daylight Time

  • cst: Central Standard Time

  • cdt: Central Daylight Time

  • mst: Mountain Standard Time

  • mdt: Mountain Daylight Time

  • pst: Pacific Standard Time

  • pdt: Pacific Daylight Time

  • yst: Yukon Standard Time

  • ydt: Yukon Daylight Time

  • hst: Hawaii Standard Time

  • hdt: Hawaii Daylight Time

  • cat: Central Alaska Time

  • akst: Alaska Standard Time

  • akdt: Alaska Daylight Time

  • ahst: Alaska-Hawaii Standard Time

  • nt: Nome Time

  • idlw: International Date Line West

  • cet: Central European Time

  • met: Middle European Time

  • mewt: Middle European Winter Time

  • mest: Middle European Summer Time

  • mesz: Middle European Summer Time

  • swt: Swedish Winter Time

  • sst: Swedish Summer Time

  • fwt: French Winter Time

  • fst: French Summer Time

  • eet: Eastern Europe Time, USSR Zone 1

  • bt: Baghdad Time, USSR Zone 2

  • zp4: USSR Zone 3

  • zp5: USSR Zone 4

  • zp6: USSR Zone 5

  • wast: West Australian Standard Time

  • wadt: West Australian Daylight Time

  • cct: China Coast Time, USSR Zone 7

  • jst: Japan Standard Time, USSR Zone 8

  • east: Eastern Australian Standard Time

  • eadt: Eastern Australian Daylight Time

  • gst: Guam Standard Time, USSR Zone 9

  • nzt: New Zealand Time

  • nzst: New Zealand Standard Time

  • nzdt: New Zealand Daylight Time

  • idle: International Date Line East



Version

PHP 3 since 3.0.12, PHP 4 since 4.0b2

Example

Example 208. Calculating dates and times using natural strings

/* When tested at 10:25 on April 17 2001,
 * the following code produced this output:
 * 10:25:31 Tuesday, Apr 17
 * 18:00:00 Tuesday, Apr 17
 * 10:25:31 Tuesday, May 15
 * 00:00:00 Monday, Apr 16
 * 10:25:31 Wednesday, Apr 18
 * 14:00:00 Monday, Apr 16
 * 07:00:00 Thursday, Apr  5
 * 10:25:31 Tuesday, Apr 17
 */

function test_time($time_string) {
    echo strftime("%X %A, %b %e\n", strtotime($time_string));
}

test_time('now');
test_time('4pm + 2 Hours');
test_time('now + 2 fortnights');
test_time('last Monday');
test_time('tomorrow');
test_time('2pm yesterday');
test_time('7am 12 days ago');

/* Calculate relative to next week, using strtotime() to generate
 * both the final result and the relative time for now.
 * This example produces, in a roundabout way, the current date. */
$now = strtotime('next week');
echo strftime("%X %A, %b %e\n", strtotime('last week', $now));



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.