Hello Everyone,
By any chance does anyone have a function that calculations the week number of the year based on day of the week starting on Sunday or Monday?
Thank you!
Hello Everyone,
By any chance does anyone have a function that calculations the week number of the year based on day of the week starting on Sunday or Monday?
Thank you!
FUNCTION WeekOfYear( dFecha )
LOCAL nDiaAnio, nSemana
// Calcula el dÃa del año (1 a 365/366)
nDiaAnio := DOY( dFecha )
// Calcula la semana (asumiendo que la semana 1 comienza el 1 de enero)
nSemana := INT( ( nDiaAnio - 1 ) / 7 ) + 1
RETURN nSemana
🔹 Ejemplo de uso:
? WeekOfYear( CTOD("02/11/2025") ) // Devuelve 45FUNCTION WeekISO( dFecha )
LOCAL dJueves, dInicioAnio, nDiaAnio, nSemana
// ISO dice que la semana se define por el jueves
dJueves := dFecha - ( DOW( dFecha ) + 5 ) % 7 + 3
// Primer jueves del año
dInicioAnio := STOD( STR( YEAR( dFecha ), 4 ) + "0104" ) - ;
( DOW( STOD( STR( YEAR( dFecha ), 4 ) + "0104" ) ) + 5 ) % 7 + 3
// Número de semana
nSemana := 1 + INT( ( dJueves - dInicioAnio ) / 7 )
RETURN nSemana
🔹 Ejemplo de uso:
? WeekISO( CTOD("02/11/2025") ) // Devuelve 44 (semana ISO)Gracias Willi
#include "Fivewin.ch"
FUNCTION MAIN()
? WEEK()
RETURN NILFunction cISO8061Week( dDate )
local dThu, nDay
#ifdef __XHARBOUR__
nDay := dDate % 7 // Mon .. Sun as 0 .. 6
#else
nDay := ( dDate - CToD( '' ) ) % 7
#endif
dThu := dDate - nDay + 3
return Str( Year( dThu ), 4 ) + '-W' + StrZero( Week( dDate ), 2 ) + '-' + Str( nDay + 1, 1 )#include 'fivewin.ch'
FUNCTION Semana( wfecha )
LOCAL wanio, wddsemana
DEFAULT wfecha:=Date()
wanio:=Year( wfecha )
wddsemana:=Dow( wfecha )
?hb_Week( wfecha, @wanio, @wddsemana )
RETURN nil#include 'fivewin.ch'
FUNCTION WeekNumber( wDate )
LOCAL wYear, wDayOfWeek
DEFAULT wDate:=Date()
wYear:=Year( wDate )
wDayOfWeek:=Dow( wDate )
?hb_Week( wDate, @wYear, @wDayOfWeek )
RETURN nil