FUNCTIONS CT

SetDate()

Change the date of the system clock

Syntax

Signature
SetDate( dDate ) --> lSuccess

Arguments

dDate

The new date, from 1 January 1970 on.

Return value

.T. when the date was set. .F. for an empty or earlier date, or when the program has no right to change the clock.

Description

SetDate() sets the local date of the computer. The time of the day stays.

Notes

Changing the clock needs the rights of an administrator on Windows and of root on Linux. Without them SetDate() gives .F. and the clock does not change.

Example

SetDate.prg
PROCEDURE Main()

   /* today again, so the clock does not really change */
   Check( 'SetDate() gives a logical value  ', ValType( SetDate( Date() ) ), "L" )
   Check( 'an empty date gives .F.          ', SetDate( CToD( "" ) ), .F. )
   Check( 'a date before 1970 gives .F.     ', SetDate( SToD( "19691231" ) ), .F. )

RETURN

STATIC PROCEDURE Check( cTitle, xResult, xExpected )

   QOut( cTitle + IIF( xResult == xExpected, "OK", "ERROR" ) )

RETURN

Output

SetDate() gives a logical value  OK
an empty date gives .F.          OK
a date before 1970 gives .F.     OK

See also