You are here: Re: first day of month from sql date. « PHP Programming Language « IT news, forums, messages
Re: first day of month from sql date.

Posted by Kimmo Laine on 11/20/06 11:31

"meltedown" <asdf@fake.com> wrote in message
news:6ka8h.32062$E_2.703@fe03.news.easynews.com...
> petersprc wrote:
>> You could do something like this:
>>
>> <?
>>
>> function firstDayOfMonth($str = '2006-11-19')
>> {
>> $day = date('l', strtotime(date('Y/m/01', strtotime($str))));
>> return $day;
>> }
>>
>> echo firstDayOfMonth();
>>
>> ?>
>>
>> Change the date format string if you want other information about the
>> first day of the month.
>>
>> meltedown wrote:
>>> If I have an sql date, such as "2006-11-19" is there a way using either
>>> sql or php date and time functions to get the date of the the first day
>>> of the month ?
>>
>
> Thanks, but I want the date, not the weekday. For 2006-11-19 it would be
> 2006-11-01

Well the answer was already given in petersprc's first post, you just need a
little part of it:

date('Y-m-01', strtotime($str)); // this takes given timestamp $str and
outputs a Y-m-d formatted date for first of the month just as you wanted.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti pδivittyvδ nettisarjis
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)

 

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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация