Help - Search - Members - Calendar
Full Version: Number of sundays in a month
HTMLHelp Forums > Programming > Databases
sania
hi all..

i need a sql query to find out number of sundays in a month..
can u help me out with this!!

thanku..
cheerio..

sania
Brian Chandler
Looks like a rather tedious bit of date arithmetic. Why do you need a MySQL query as such? If you are using PHP I expect it's easier to do with php's date function than MqSQL's stuff.
sania
QUOTE(Brian Chandler @ May 28 2007, 12:50 PM) *

Looks like a rather tedious bit of date arithmetic. Why do you need a MySQL query as such? If you are using PHP I expect it's easier to do with php's date function than MqSQL's stuff.

thanks brian..

am doing an application using both mysql and php platforms.. so let me know the solution using the date function of php.. it'll be helpful to me..

cheerio
sania..
Brian Chandler
Well, you need to read the manual for the php functions: one converts a set of values like Year, Month, Day into a "datestamp" value; the other extracts useful information from a datestamp, back into human readable form. For no reason that I can imagine, one of these functions is called "date" and the other "time" (the difference between them is not remotely connected to the difference between date and time, but hey, welcome to modern programming!)

http://jp.php.net/manual/en/function.date.php
http://jp.php.net/manual/en/function.time.php

I assume you want a function like sundays($year, $month) that returns the number of sundays? So:

Get the timestamp for date $year - $month - 1
Get from it the day of the week (as a number, for convenience)
Subtract from 7 (plus-minus 1) to get the date of the first sunday.
Find the number of days in the month
Subtract the date of the first sunday (plus-minus 1), and divide by 7, rounding down (plus-minus 1).
This gives you the answer

You will need to be careful, because of all these (plus-minus 1) bits - the fact that you could probably easily have up to 3 one-off errors in either direction makes just using a random person's function alleged to do this to be a dubious proposition.

sania
thanku brain..
it helped me a lot...
is der any function in php which convets numerical values into english words in php? like 1 into one!!

cheerio..
sania..
Brian Chandler
Dunno.

Try here: http://php.net/manual/en/index.php
and here: http://google.com
viju
I want to know about the select statement which could access the same record from two different tables.
Brian Chandler
QUOTE(viju @ Jan 7 2008, 04:55 PM) *

I want to know about the select statement which could access the same record from two different tables.


Then why are you asking in a thread about something else?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.