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 bkrike 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 computer datetime by vfp

Status
Not open for further replies.

ZooMoo

IS-IT--Management
May 16, 2002
11
TH
Someone help me please, In my application, I let user make sure about system date time is correctly, If not user can change date time on his/her computer by my application, currently version I passing date time to setting into system by run command in DOS, Now I want to set it in better way by using API but I don't know about it. Help me please
 
This will do it for you. Just make sure the user's system is set to the correct setting in Windows . Ie this function returns "Coordinated Universal Time (UTC)"

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)
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top