Are there time functions :09:01+5-->:09:06

Post Reply
ShumingWang
Posts: 454
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Are there time functions :09:01+5-->:09:06

Post by ShumingWang »

Hi,
Are there functions like:
09:01 +5 --> 09:06
09:01 -08:01--> 01:01
Thanks !
Shuming Wang
User avatar
pablovidal
Posts: 398
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana
Contact:

Post by pablovidal »

Estas Funciones las encontr en el Foro hace muchos años atras
Espero te sirvan...

Code: Select all


*+--------------------------------------------------------------------
*+
*+    Function TimeAsSeconds()
*+
*+--------------------------------------------------------------------
*+
FUNCTION TimeAsSeconds( cTime )

RETURN VAL( cTime ) * 3600 + VAL( SUBSTR( cTime, 4 ) ) * 60 + VAL( SUBSTR( cTime, 7 ) )

*+--------------------------------------------------------------------
*+
*+    Function TimeAsSeconds()
*+
*+--------------------------------------------------------------------
*+
FUNCTION TimeAsMinute( cTime )
LOCAL nSEC := VAL( cTime ) * 3600 + VAL( SUBSTR( cTime, 4 ) ) * 60 //+ VAL( SUBSTR( cTime, 7 ) )
RETURN( nSEC / 60 )

*+--------------------------------------------------------------------
*+
*+    Function TimeAsString()
*+
*+--------------------------------------------------------------------
*+
FUNCTION TimeAsChar( nSeconds )

RETURN STRZERO( INT( MOD( nSeconds / 3600, 24 ) ), 2, 0 ) + ;
                STRZERO( INT( MOD( nSeconds / 60, 60 ) ), 2, 0 ) + ;
                STRZERO( INT( MOD( nSeconds, 60 ) ), 2, 0 )

*+--------------------------------------------------------------------
*+
*+    Function TimeAsString()
*+
*+--------------------------------------------------------------------
*+
FUNCTION TimeAsString( nSeconds )

RETURN STRZERO( INT( MOD( nSeconds / 3600, 24 ) ), 2, 0 ) + ":" + ;
                STRZERO( INT( MOD( nSeconds / 60, 60 ) ), 2, 0 ) + ":" + ;
                STRZERO( INT( MOD( nSeconds, 60 ) ), 2, 0 )

*+--------------------------------------------------------------------
*+
*+    Function TimeDiff()
*+
*+--------------------------------------------------------------------
*+
FUNCTION TimeDiff( cStartTime, cEndTime )
Default cEndTime := Time()
RETURN TimeAsString( IF( cEndTime < cStartTime, 86400, 0 ) + ;
                     TimeAsSeconds( cEndTime ) - TimeAsSeconds( cStartTime ) )

*+--------------------------------------------------------------------
*+
*+    Function TimeIsValid()           20:20:00
*+
*+--------------------------------------------------------------------
*+
FUNCTION TimeIsValid( cTime )
RETURN VAL( cTime ) < 24 .AND. VAL( SUBSTR( cTime, 4 ) ) < 60 .AND. VAL( SUBSTR( cTime, 7 ) ) < 60


Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
jose_murugosa
Posts: 943
Joined: Mon Feb 06, 2006 4:28 pm
Location: Uruguay
Contact:

Re: Are there time functions :09:01+5-->:09:06

Post by jose_murugosa »

ShumingWang wrote:Hi,
Are there functions like:
09:01 +5 --> 09:06
09:01 -08:01--> 01:01
Thanks !
Shuming Wang

This ar native functions of xharbour:

Secs()
Calculates the number of seconds from a time string.
Syntax
Secs( <cTime>|<dDateTime> ) --> nSeconds

TString()
Converts numeric seconds into a time formatted character string.
Syntax
TString( <nSeconds> ) --> cTimeString

I hope It may help.
Saludos/Regards,
José Murugosa
FWH + Harbour + Bcc7. Una seda!
ShumingWang
Posts: 454
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Post by ShumingWang »

pablovidal,jose_murugosa,
Thank you!
Shuming Wang
Post Reply