Reply to Re: Calculate timestamp 00:00:00 last sunday

Your name:

Reply:


Posted by Rik on 07/17/06 11:56

griemer wrote:
> mmmm, i'm a little confused now.
> Not about wich day is the first day of the week, but on how 'last
> sunday' is calculated.
>
> Obviously, when you're talking about 'last sunday' on a sunday,
> you're talking about the sunday which was a week ago.
>
> BUT........
>
> I think i have to say it a little different: How do i calculate the
> total amount of seconds that have past since the last transition from
> saturday to sunday.
>
> So, every day of the week this is 'last sunday' , exept on sundays,
> then its 'today
>
>
> So the amount will never by more than 3600 * 24 * 7 seconds.
>
> I also like to know the date of that sunday

I'm not fond of strototime(), so let't do it by hand:

function last_sunday($date = false){
if($date===false) $date = time();
$last_sunday =
mktime(0,0,0,date('n',$date),date('j',$date),date('Y',$date)) - (24 * 60 *
60 * date('w',$date));
return $date - $last_sunday; //number of seconds since last transition
}

Will return the number of seconds since last sunday 00:00:00, calculated
from date, or from time() if not givem.

Grtz,
--
Rik Wasmus

[Back to original 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

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