NYCPHP Meetup

NYPHP.org

[nycphp-talk] Formatting dates

Hans Zaunere zaunere at yahoo.com
Wed May 15 18:35:30 EDT 2002


Several ways of doing this - here is some tips that might help.

--- jose sanchez <j_r_sanchez at yahoo.com> wrote:
> Hello:
> 
> I would like to know how I can use dates in PHP.
> 
> This is what I would like to accomplish:
> 
> First I would like to assign a starting date, for
> example:
> 5/11/02.

$start_timestamp = mktime(0,0,0,5,11,2002);

> 
> I would like to add seven days to it so it will be
> Sat. May 18th and one day so it can be Sun. May 19th.

define('SECSINDAY', 24*3600);
define('SECSINWEEK', SECSINDAY*7);

$sat_timestamp = $start_timestamp + SECSINWEEK;
$sun_timestamp = $sat_timestamp + SECSINDAY;

> 
> I would like to do this for every week. At the same
> time, assign a week number according to the date. For
> example; May 11th and 12th would be week #1. Now, May
> 18th and 19th would be week #2 and so on...

Since you'll be starting at an arbitrary date, you'll need to track the
weeks on your own.  However, maybe you could setup an offset, and
subtract that from the yearly week count (using date()).

> 
> I know it will be a problem when the month changes. In
> other words what I like to create is a schedule thats
> in a database and loaded according to the week_no.
> 
> Any idea on how I can accomplish this.

If your using MySQL, there are some very useful date/time
subtraction/addition functions (DATE_ADD() or something like that).

Hope this helps,

Hans Z.



> Your help would be very apreciated.


> 
> Thank you.
> 
> =====
> "An ounce of gold cannot buy an ounce of time."
> - Anonymous
> 
> 
> www.whmicro.com
> 
> __________________________________________________
> Do You Yahoo!?
> LAUNCH - Your Yahoo! Music Experience
> http://launch.yahoo.com
> 


__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com



More information about the talk mailing list