Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
I was asked
Is there a way to translate the timestamp in a VCX to a human readable format?
Visual Foxpro puts a timestamp on many records in the table that represents a form or class library. Historically this field was used to match records across supported platforms: DOS, Mac, Unix, Windows.
The VFP reserved variable “_screen” is an object reference to the Form instance that represents the VFP desktop. Because it’s a form instance, you can save it as a class using the SaveAsClass method. This will cause a timestamp record to be created that we can use to run the sample code. The sample code delays 3 seconds, creates a subclass of the form, adds a button, then shows the timestamps of the items in the class library.
The timestamp is in a standard format.
ERASE t.vcx
_screen.AddObject("btn","commandbutton") && add a button to the desktop
_screen.SaveAsClass("t.vcx","myform") && create class myform in a target file t.vcx
INKEY(3) && delay 3 seconds
MODIFY CLASS xx OF t.vcx as myform FROM t.vcx nowait && create a subclass of myform in the same file
ASELOBJ(aArray,1) && get an object reference to the class in the designer
aArray[1].addobject("btn2","commandbutton") && and btn2 to the class
aArray[1].btn2.top=200 && move it down so it doesn't hide btn
KEYBOARD "Y" && a "y" in the "Do you want to save changes")
RELEASE WINDOWS "Class designer" && close the designer
USE t.vcx && open the table
SCAN FOR timestamp!=0 && look for timestamps
?timestamp,DecodeTimeStamp(timestamp),objname+" "+class
ENDSCAN
PROCEDURE DecodeTimeStamp(nTimestamp as Number) as Datetime && see https://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/filetimetodosdatetime.asp
nDate=BITRSHIFT(nTimestamp,16)
nTime=BITAND(nTimestamp,2^16-1)
nYear=BITAND(BITRSHIFT(nDate,9),2^8-1)+1980
nMonth=BITAND(BITRSHIFT(nDate,5),2^4-1)
nDay=BITAND(nDate,2^5-1)
nHr=BITAND(BITRSHIFT(nTime,11),2^5-1)
nMin=BITAND(BITRSHIFT(nTime,5),2^6-1)
nSec=BITAND(nTime,2^5-1)
RETURN DATETIME(nYear,nMonth,nDay,nHr,nMin,nSec)
RETURN
48662
Anonymous
January 22, 2005
***********************************
Name : TimeStamp2DataTime
Call : tnTimeStamp = 586250725
? TimeStamp2DataTime(tnTimeStamp)
Return : 1997/07/17 15:15:10
From : Tuberose, Shanghai, China
**************************************
tnTimeStamp = 586250725
? TimeStamp2DataTime(tnTimeStamp)
FUNCTION TimeStamp2DataTime
PARAMETERS lcRetVal
! Lparameter tnTimeStamp, tcStyle
! Local lcRetVal
SET DATE YMD
If Type('tnTimeStamp') <> "N"
Wait Window "Not Number"
Return ""
Endif
If tnTimeStamp = 0
Return "Error TimeStamp"
Endif
If Type('tcStyle') <> "C"
tcStyle = "DATETIME"
Endif
If .Not. Inlist(Upper(tcStyle), "DATE", "TIME", "DATETIME")
Wait Window "Type Must is : DATE、TIME or DATETIME"
Return ""
Endif
lnYear = ((tnTimeStamp/(33554432)+1980))
lnMonth = ((lnYear-Int(lnYear))(33554432))/(2097152)
lnDay = ((lnMonth-Int(lnMonth))(2097152))/(65536)
lnHour = ((lnDay-Int(lnDay))(65536))/(2048)
lnMinute = ((lnHour-Int(lnHour))(2048))/(32)
lnSecond = ((lnMinute-Int(lnMinute))*(32))*2
lcRetVal = Space(0)
If "DATE" $ Upper(tcStyle)
lcRetVal = lcRetVal + Dtoc(Date(lnYear, lnMonth, lnDay))
Endif
lcSeparator = ":"
If "TIME"$Upper(tcStyle)
lcRetVal = lcRetVal + Iif("DATE" $ Upper(tcStyle), " ", "")
lcRetVal = lcRetVal + Right("0" + Alltrim(Str(Int(lnHour))), 2)+lcSeparator+;
Right("0" + Alltrim(Str(Int(lnMinute))), 2) + lcSeparator + ;
Right("0" + Alltrim(Str(Int(lnSecond))), 2)
Endif
Return lcRetVal
Anonymous
January 20, 2009
PingBack from http://www.hilpers-esp.com/318788-acelerar-el-entorno-de-datos
Anonymous
June 16, 2013
Function DT2TimeStamp(dtDateTime)
Return Bitlshift(Bitlshift(Year(dtDateTime)-1980,9)+Bitlshift(Month(dtDateTime),5)+Day(dtDateTime),16) ;
+ BITLSHIFT(hour(dtDatetime),11)+BITlSHIFT(Minute(dtDateTime),5)+Sec(dtDateTime)
source : www.atoutfox.org/articles.asp
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in