Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Time Elapsed
Message
De
06/06/2002 10:20:27
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00665357
Message ID:
00665424
Vues:
25
One additional function that may address your particular case. Pass datetime values for start and end times. Pass a third parameter to format return value.
FUNCTION timediff
	PARAMETERS m.adt_datetime1,m.adt_datetime2,m.adt_retcode
**********************************************************************
*PROC/FUNC--> timediff - RETURNS THE DIFFERENCE BETWEEN 2 datetimes
*---------------------------------------------------------------------
	*parameter1 = datetime of beginning time
	*parameter2 = datetime of end time
	*parameter3 = not passed or = "HH:MM:SS" returns difftime in character string in format hours:minutes:seconds
	*parameter3 = "HOURS"  returns difftime as in character string as number of hours and factional hours
	*parameter3 = any other third parameter returns difftime as in character string in format X days hours:minutes:seconds
	*calculates difference between two points in time
	*returns difference in two times (default HH:MM:SS unless param 3 is passed)
	local m.adt_total,m.adt_negtime,m.hourscalc,m.adt_hours,m.minutescalc,m.adt_minutes,m.adt_seconds,m.adt_days
	STORE .F. TO m.adt_negtime  && if datetime1 > datetime2 yields negative result

	IF TYPE("m.adt_datetime1") = "T" .AND. TYPE("m.adt_datetime2") = "T"
		*!*PARAMETERS OK
	ELSE
		=messagebox("Error : Invalid date to timediff Function","Parameter Error")
		m.adt_total = "ERROR"
		RETURN m.adt_total
	ENDIF
	if m.adt_datetime2 > m.adt_datetime1
		m.hourscalc = int(m.adt_datetime2 - m.adt_datetime1)
	else
		m.adt_negtime  = .t.
		m.hourscalc = int(m.adt_datetime1 - m.adt_datetime2)
	endif
	m.minutescalc = mod(m.hourscalc,3600)
	m.adt_hours = int(m.hourscalc/3600)
	m.adt_minutes = int(m.minutescalc/60)
	m.adt_seconds = mod(m.minutescalc,60)
	do case 
	case Pcount() < 3 .or. upper(m.adt_retcode) = "HH:MM:SS" 
 		*parameter3 = return HH:MM:SS format
		m.adt_total = iif( m.adt_negtime = .t.," - ","")+;
			alltrim(str(m.adt_hours))+;
			":"+padl(alltrim(Str(m.adt_minutes)),2,"0")+;
			":"+padl(alltrim(Str(m.adt_seconds)),2,"0")
	case upper(m.adt_retcode) = "HOURS"
 		*parameter3 = return hours format
         m.adt_hours = m.adt_hours+(m.minutescalc/3600)
			m.adt_total = iif( m.adt_negtime = .t.," - ","")+;
			alltrim(str(m.adt_hours,10,4))
	otherwise
		*parameter3 = return days and hours format
		m.adt_days = int(m.adt_hours/24)
		m.adt_hours = mod(m.adt_hours,24)
		m.adt_total = iif( m.adt_negtime = .t.," - ","")+;
			alltrim(str(m.adt_days))+" DAYS "+;
			alltrim(str(m.adt_hours))+;
			":"+padl(alltrim(Str(m.adt_minutes)),2,"0")+;
			":"+padl(alltrim(Str(m.adt_seconds)),2,"0")
	endcase
	RETURN m.adt_total
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform