Sunday calc

Sunday calc

Postby Eoeo » Tue Sep 18, 2012 5:21 pm

How I can calculate how many sundays there are in a month ?
User avatar
Eoeo
 
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: Sunday calc

Postby sambomb » Tue Sep 18, 2012 5:52 pm

Code: Select all  Expand view

Function GetSunday( nMonth, nYear )
Local nCont := 0, nSunday := 0, dDayIni := cTod("01/"+StrZero(nMonth,2)+"/"+StrZero(nYear,4))

   While Month(dDayIni+nCont) = nMonth
      If Dow(dDayIni+nCont++) = "Sunday"
         nSunday++
      end
   end

Return nSunday

 
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Sunday calc

Postby nageswaragunupudi » Tue Sep 18, 2012 5:57 pm

Code: Select all  Expand view
function Sundays( dDate )

   local x, d := EOM( dDate )

return If( ( x := Day( d ) - 28 ) == 0 .or. dow( d ) > x, 4, 5 )
 


Usage: Sundays( STOD( "20120101" ) ) --> Sundays in Jan 2012
Sundays( Date() ) --> Sundays in Sep 2012
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Sunday calc

Postby Eoeo » Tue Sep 18, 2012 9:37 pm

Mr Nages Ineed the number of sunday in a month sample

september there are 30 days with 5 sundays

this I need to calculate the work Hour in this month

this run ok ( thanks to all )

Function GetSunday( nMonth, nYear )
Local nCont := 0
Local nSunday := 0
Local dInizio := cTod("01/"+StrZero(nMonth,2)+"/"+StrZero(nYear,4))
nSunday:=Sundays(dInizio)
Return nSunday


function Sundays( dDate )
local x, d := EOM( dDate )
return If( ( x := Day( d ) - 28 ) == 0 .or. dow( d ) > x, 4, 5 )
User avatar
Eoeo
 
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: Sunday calc

Postby nageswaragunupudi » Wed Sep 19, 2012 3:02 am

Code: Select all  Expand view
function GetSundays( nMonth, nYear )

   local x, d := EOM( STOD( Str( nYear, 4 ) + StrZero( nMonth, 2 ) + '01' ) )

return If( ( x := Day( d ) - 28 ) == 0 .or. dow( d ) > x, 4, 5 )
 


CTOD() depends on SET DATE setting. Using STOD is safer.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Sunday calc

Postby Eoeo » Wed Sep 19, 2012 8:24 am

thanks
User avatar
Eoeo
 
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 94 guests