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 strawberry on 11/20/06 09:56

meltedown wrote:

> petersprc wrote:
> > You could work on the text:
> >
> > $date = '2006-11-19';
> > $newDate = substr($date, 0, strrpos($date, '-')) . '-01';
> >
> > meltedown wrote:
> >> 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
> >
>
> Yes I know but I'd rather not.

This from Azizur Rahman at

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

To get the first day of the current month:

SELECT ((PERIOD_ADD(EXTRACT(YEAR_MONTH FROM CURDATE()),0)*100)+1) as
FirstDayOfTheMonth;

 

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

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