You are here: Re: [PHP] Week Days « PHP « IT news, forums, messages
Re: [PHP] Week Days

Posted by Robert Cummings on 10/19/33 11:24

On Sat, 2005-08-20 at 00:00, Richard Lynch wrote:
> On Thu, August 18, 2005 10:57 pm, benc11@gmail.com wrote:
> > I am trying to add 3 (or a user-defined amount) week days to a certain
> > date..
> > An example is today 2005-08-18 then adding 3 week days to give me a
> > date of
> > 2005-08-23. I have tried searching online but cannot find an easy way
> > of
> > doing so.
>
> Assuming you are willing to ignore holidays, which in most real-world
> applications, you're not...
>
> <?php
> $certain_date = '8/19/2005';
> $week_days = '...';
> list($m, $d, $y) = explode('/', $certain_date);
> $start = mktime(0, 0, 0, $m, $d, $y);
> //Every 5 days is a full week:
> $weeks = floor($week_days/5);
> $close = mktime(0, 0, 0, $m, $d + $weeks * 7, $y);
> $remainder = $week_days % 5;
> for ($added = 0, $day = 0; $added < $remainder; $day++){
> $dow = date('w', $close + $day*60*60*24); //Is it 'w' for 'day of
> week'?
> if ($dow == 0 || $dow == 1){ //0|1 are Sun/Sat, right?

No, 6 is saturday :B You know, I was looking for which fricking macro
expanded to a non locale based indicator for the day of the week
yesterday (ala the 'w' for date()). I guess my eyes were getting fuzzy
*grin*.

Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

 

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

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