You are here: Re: getting first day and last day of month « PHP Programming Language « IT news, forums, messages
Re: getting first day and last day of month

Posted by Oli Filth on 11/01/48 11:41

Sjoerd said the following on 03/03/2006 10:58:
> laredotornado@zipmail.com wrote:
>> Hi, Using PHP 4, if I have a date, what is a function I could use to
>> give me a date that represents the first day of that month? For
>> example, if my date were "3/19/2006 8:00", I would want my function to
>> return "3/1/2006 8:00". Similarly what function would I use to return
>> the last day of the month? In the above example, the output I would
>> want returned is "3/31/2006 8:00".
>
> The first date of the month is trivial: replace the day number with 1.
> The last day of the month is somewhat harder, because this varies with
> months and leap years. However, you could use checkdate to figure out
> what the last day of the month is:
>
> function getlastdayofmonth($month, $year) {
> for ($day = 28; $day < 32; $day++) {
> if (!checkdate($month, $day, $year)) return $day-1;
> }
> }
>

Or more directly:

function getLastDayOfMonth($month, $year)
{
return idate('d', mktime(0, 0, 0, ($month + 1), 0, $year));
}

--
Oli

 

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

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