Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Luis Maria Guayan
  Where is Luis Maria Guayan?
 Yerba Buena
 Argentina
 Luis Maria Guayan
 To: Ilya Rabyy
  Where is Ilya Rabyy?
 Fountain Valley
 California - United States
 Ilya Rabyy
 Tags
Subject: RE: Set date programmatically - HOWTO?
Thread ID: 331190 Message ID: 331196 # Views: 49 # Ratings: 2
Version: Visual FoxPro 9 SP2 Category: Network and Computer Management
Date: Tuesday, December 27, 2011 6:18:37 PM         
   


> Colleagues,
>
> Suppose you need to test some program that manages the period data, say - for the month of January, February, etc., and it determines this periood by the today's date's month (i.e., December, like - now), and you need to test it for another month.
>
> IOW, if it's today (December) - then your program would pick up the data (by the date field in a table) for November.
>
> However, you need to have your system date set to January temporarily.
>
> Besides the obvious move (changing the system date on your PC by clicking on that date/time pad in the right corner of the Task Bar) - is there any way to set the date programmatically in VFP? (Needless to say that I'd like to move the system date in a test launcher program, and resore it back to the today's date at the end of this launcher program.)
>
> Any ideas?
>
> TIA!
>
> Regards,
>
> Ilya

See this old functions

? ReadLocalTime()

? WriteLocalTime(DATETIME(2011,12,28,18,00,00))

*------------------------
FUNCTION ReadLocalTime()
  *------------------------
  * Lee mediante API el GetLocalTime
  * Retorno: DATETIME o .NULL. si existe error
  * Autor: LMG - 1998.09.14
  *------------------------
  LOCAL lcAuxi, ltDateTime, ;
    lcSetDate, lcSetHours, lcSetCentury, ;
    lcSetSysformats, lcSetMark

  lcSetSysformats = SET("SYSFORMATS")
  lcSetCentury = SET("CENTURY")
  lcSetDate = SET("DATE")
  lcSetHours = SET("HOURS")
  lcSetMark = SET("MARK")

  SET SYSFORMATS OFF
  SET CENTURY ON
  SET DATE YMD
  SET HOURS TO 24
  SET MARK TO "/"

  DECLARE GetLocalTime IN win32api ;
    STRING @lcAuxi

  lcAuxi=SPAC(32)

  IF GetLocalTime(@lcAuxi)
    ltDateTime = CTOT( _256to10(SUBS(lcAuxi,1,2), 4) + "/" + ;
      _256to10(SUBS(lcAuxi,3,2), 2) + "/" + ;
      _256to10(SUBS(lcAuxi,7,2), 2) + " " + ;
      _256to10(SUBS(lcAuxi,9,2), 2) +  ":" + ;
      _256to10(SUBS(lcAuxi,11,2), 2) + ":" + ;
      _256to10(SUBS(lcAuxi,13,2), 2) )
  ELSE
    ltDateTime = .NULL.
  ENDIF

  SET MARK TO &lcSetMark
  SET HOURS TO &lcSetHours
  SET DATE &lcSetDate
  SET CENTURY &lcSetCentury
  SET SYSFORMATS &lcSetSysformats

  RETURN ltDateTime
ENDFUNC

*------------------------
FUNCTION WriteLocalTime(ltDateTime)
  *------------------------
  * Escribe mediante API el GetLocalTime
  * Parametro: Debe pasarse una variable del tipo DateTime
  * Retorno: .T. si pudo cambiar fecha y hora
  *          .F. envio un parámetro no válido o error
  * Autor: LMG - 1998.09.14
  *------------------------
  IF TYPE("ltDateTime") # "T"
    RETURN .F.
  ENDIF

  LOCAL lcCadena

  lcCadena = _10to256(YEAR(ltDateTime),2) + ;
    _10to256(MONTH(ltDateTime),2) + ;
    _10to256(DOW(ltDateTime),2) + ;
    _10to256(DAY(ltDateTime),2) + ;
    _10to256(HOUR(ltDateTime),2) + ;
    _10to256(MINUTE(ltDateTime),2) + ;
    _10to256(SEC(ltDateTime),2) + ;
    _10to256(000,2) + SPAC(24)

  DECLARE SetLocalTime IN win32api ;
    STRING lcCadena

  RETURN SetLocalTime(lcCadena)
ENDFUNC

*------------------------
FUNCTION _256to10(lcPar, lnCant)
  *------------------------
  * Usada por: ReadLocalTime()
  * Autor: LMG - 1998.09.14
  *------------------------
  RETURN PADL(ALLTRIM(STR(ASC(SUBSTR(lcPar,2)) * 256 + ;
    ASC(SUBSTR(lcPar,1)))), lnCant, "0")
ENDFUNC

*------------------------
FUNCTION _10to256(lnNumero, lnCant)
  *------------------------
  * Usada por: WriteLocalTime()
  * Autor: LMG - 1998.09.14
  *------------------------
  LOCAL lcRetorno, lnAscii

  lcRetorno=''
  DO WHILE lnNumero >= 256
    lnAscii=MOD(lnNumero,256)
    lcRetorno=lcRetorno + CHR(lnAscii)
    lnNumero=INT(lnNumero / 256)
  ENDDO
  lnAscii=lnNumero
  lcRetorno=lcRetorno + CHR(lnAscii)
  RETURN PADR(lcRetorno, lnCant, CHR(0))
ENDFUNC
*------------------------


Luis María Guayán
Tucumán, Argentina
________________________________
SysOp de www.PortalFox.com

ENTIRE THREAD

Set date programmatically - HOWTO? Posted by Ilya Rabyy @ 12/27/2011 5:11:33 PM
RE: Set date programmatically - HOWTO? Posted by M. Tanveer Ul Hassan Shaheen @ 12/27/2011 6:03:38 PM
RE: Set date programmatically - HOWTO? Posted by Luis Maria Guayan @ 12/27/2011 6:18:37 PM
RE: Set date programmatically - HOWTO? Posted by Ilya Rabyy @ 12/27/2011 6:37:57 PM
RE: Set date programmatically - HOWTO? Posted by Pete Sass @ 12/27/2011 6:29:12 PM