Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set the computer's system time

Usefull Functions & Procedures

How to set the computer's system time

by  Mike Gagnon  Posted    (Edited  )
*Note : This API function will reset the system time accoding to the Coordinated Universal Time (UTC). Depending where you are in the world, you have to adjust the hours to the appropriate value and the time of the year (to accomodate the Eastern Standard time) Example in Eastern Canada the adjustment in July would be

lnhour = hour(ltcurrent)-4

Code:
Declare integer SetSystemTime in kernel32 STRING@
local lcsystemtime, lnyear, lnmonth, lndayofweek, lnday, lnhour, lnminute, lnsecond, lnmillsecond,ltcurrent
lcsystemtime = space(0)
ltcurrent = datetime()

lnyear = year(ltcurrent)
lnmonth = month(ltcurrent)
lndayofweek = dow(ltcurrent)
lnday = day(ltcurrent)
lnhour = hour(ltcurrent) && Adjustment require
lnminute = minute(ltcurrent)
lnsecond = sec(ltcurrent)
lcsystemtime = NumtoWord(lnyear)+NumtoWord(lnmonth)+NumtoWord(lndayofweek)+NumtoWord(lnday)+ ;
      NumtoWord(lnhour)+NumtoWord(lnminute)+NumtoWord(lnsecond)+NumtoWord(0)
nres = SetSystemTime(@lcsystemtime)
llretval = nres # 0
return llretval

function NumtoWord
lparameter tnNum
lcresult = chr(0)+chr(0)
if tnNum < (2^15 - 1) then
   lcresult = chr(mod(tnNum,256))+chr(int(tnNum/256))
else
   * not a valid number for a WORD value
endif
return lcresult
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top