You are here: Re: [PHP] time() « PHP « IT news, forums, messages
Re: [PHP] time()

Posted by Marcus Bointon on 07/29/05 11:04

On 29 Jul 2005, at 08:37, <virtualsoftware@gmail.com>
<virtualsoftware@gmail.com> wrote:

> I have the date when users registered stored in the database using
> time() function format.

Hm. I hope this means you're storing it as a TimeStamp format, or
better, DateTime, and not as a simple integer field.

> I have to search for users that are registered this week, this
> month and this year. How can i do that? I mean how can i found the
> beginning of this week? Or the beginning of this month?

If you are storing it as a DateTime field, MySQL has loads of date
related functions for doing this, and it's more efficient to do it
using MySQL's functions that the equivalent in PHP. Take a look here:
http://dev.mysql.com/doc/mysql/en/date-and-time-types.html and http://
dev.mysql.com/doc/mysql/en/date-and-time-functions.html

You can do the calculations in PHP. For example, to find the first
day of this month as a timestamp:

$first = strtotime(date('Y-m-01'));

strtotime has some wonderful functionality - you can ask for dates
like 'next week' 'last year' 'yesterday -1 week'.

To format a timestamp into a MySQL-compatible DateTime string, use:

$datetime = date('Y-m-d h:i:s', $timestamp);

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcus@synchromedia.co.uk | http://www.synchromedia.co.uk

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация