Re: how to use the function "strtotime"
| From: | * R&zE: | Date: | Thu, 20 Sep 2001 09:49:02 +0000 |
| Subject: | Re: how to use the function "strtotime" | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-67963@lists.php.net to get a copy of this message | ||
<Original message>
From: mydata <muyuan11@sian.com>
Date: Thu, Sep 20, 2001 at 11:41:09AM +0800
Message-ID: <20010920033656.96921.qmail@pb1.pair.com>
Subject: [PHP] how to use the function "strtotime"
> Hi,
> I'm php developer beginner in China,but I am confused with function
> "strtotime".
> yes ,I know the usage of function "strtotime" in php manual. But description
> of php manual about it is too little.I want to know more about it.
</Original message>
<Reply>
It's not all that difficult, really. It's exactly how it's described
in the manual. Here is some code that runs some samples:
(I must say, though, that most examples can be done a lot easier
without strtotime(), but 'cause these are examples of strtotime()...
well... you know :)
--- PHP Example Code ---
<PRE>
<?php
/* Show a given date (+time) */
print ("Date: \n\t");
print (date ("r", strtotime ("January 31 2000 19:20:15"))."\n\n");
/* Show the current date (+time) */
print ("Now: \n\t");
print (date ("r", strtotime ("now"))."\n\n");
/* Show the date (+time) of tomorrow */
print ("Tomorrow: \n\t");
print (date ("r", strtotime ("tomorrow"))."\n\n");
/* Show the date (+time) of yesterday */
print ("Yesterday: \n\t");
print (date ("r", strtotime ("yesterday"))."\n\n");
/* Show the date (+time) of yesterday, where now is tomorrow. So the
the output will be today :) */
print ("Yesterday, where 'now' is tomorrow: \n\t");
print (date ("r", strtotime ("yesterday",
strtotime("tomorrow")))."\n\n");
/* Show the date (+time) 13 days from december 24th 1998 */
print ("13 days from december 24th 1998: \n\t");
print (date ("r", strtotime ("+13 days", strtotime("December 24
1998")))."\n\n"»
/* Let's say you get some date from the db (or something) and you
* want to
add 2 years and 4 months and 23 days. */
print ("Well... just see: \n\t");
$date_from_db = "2001-09-20";
print (date ("r", strtotime ("+2 years +4 months +23 days",
mktime(0,0,0,substr($date_from_db, 5, 2),
substr($date_from_db, 8, 2),
substr($date_from_db, 0, 4))))."\n\n");
/* Etc. */
print ("And so on... :)<HR noshade size=\"1\">");
?>
</PRE>
--- End of PHP Example Code ---
</Reply>
--
* R&zE:
-- »»»»»»»»»»»»»»»»»»»»»»»»
-- Renze Munnik
-- DataLink BV
--
-- E: renze@datalink.nl
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- ««««««««««««««««««««««««