Re: mysql/php date functions..
| From: | Silvio Porcellana | Date: | Mon, 26 Sep 2005 15:50:42 +0000 |
| Subject: | Re: mysql/php date functions.. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-223200@lists.php.net to get a copy of this message | ||
Jim Moseby wrote:
>
> Hi Bruce!
>
> MySQL and PHP both have extensive built-in date functions that are clearly
> documented and extraordinarily easy to use. For the vast majority of
> situations, there is no need to manually write any custom date-handling
> code. The decision to use MySQL or PHP to manipulate a date for a given
> instance depends largely on the particulars of that situation.
>
> For instance, if you want to increment a MySQL date column by one day, it
> would likely be better to use the MySQL date functions to do it, because to
> use PHP, you have to read the date, manipulate it, then write it back,
> whereas if you use a SQL statement, you can do it with one DB call.
>
> See:
> http://www.php.net/datetime
> http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
>
> Cheers!
>
Just my 0.02 euros.
When I need to use dates in PHP *and* MySQL I usually use the UNIX
timestamp (seconds since the epoch, that is, the PHP http://php.net/time
output).
This way I can (quite) easily calculate date differences etc. (usually
all the calculations are done in PHP, also when building SQL queries).
As I said, just my 0.02 euros...
Cheers
Silvio