Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Datetime Storage
Message
From
13/10/2005 18:38:36
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
13/10/2005 18:30:58
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01058915
Message ID:
01058927
Views:
31
>>For my own information, does anyone know the format of the storage of a datetime value in a table?
>>
>>I've look at this and can't discern how VFP is reading the value. It doesn't seem to be a FILETIME structure, nor a SYSTEMTIME structures.
>>
>>Any one know this?
>
>Hi George,
>It stores it as 2 integers. 1st part is Julian day number (sys(1)). 2nd part is milliseconds since midnight.
>Cetin

This is what I wrote about it in another forum:

Rick,
Assuming you want it in Foxpro's own datetime format (in C related areas a datetime structure is defined in many different ways - ie: A filetime structure is converted differently than a WMI datetime structure or SQLCDatetime structure).

Foxpro holds the datetime like this (and many other backends):
8 bytes total: 2 32bits integers.
First integer is the Julian day number. Foxpro holds seconds * 1000 in other part (might not be exactly * 1000 but milliseconds in that part - see a recent discussion about it on universalthread).
So you might do it like this:
k = datetime()
cDateTime = Date2Str(m.k)
my_custom_dll_function(m.cDateTime)


Function Date2Str
Lparameters ttValue
Local lcDay,lcTime,ix,lcDateTimeStr
lcDay  = Transform(Val(Sys(11,m.ttValue)),'@0')
lcTime = Transform((m.ttValue - Dtot(Ttod(m.ttValue))) * 1000,'@0')
lcDateTimeStr = ''
For m.ix=4 To 1 Step -1
  lcDateTimeStr = m.lcDateTimeStr +  Substr(m.lcDay,m.ix*2+1,2)
Endfor
For m.ix=4 To 1 Step -1
  lcDateTimeStr = m.lcDateTimeStr +  Substr(m.lcTime,m.ix*2+1,2)
Endfor
Return m.lcDateTimeStr
If you've used Foxpro API (location is different depending on version, generally home()+'samples\API') it has a Value structure to pass parameters. In that Value stucture ev_type is 'T' and ev_real is a double precision folting point number representing a datetime (time part is fraction). But I think you'd be fine with the above code. DLL might be expecting datetime in more common C datetime formats like a SystemTime structure (where year, month, day ... millisecond are defined as WORD). For this type you might do the conversion:
lcSysTime = N2S(Year(m.ttDateTime), 2) + ;
  N2S(Month(m.ttDateTime), 2) +;
  N2S(Dow(m.ttDateTime), 2) + ;
  N2S(Day(m.ttDateTime), 2) +;
  N2S(Hour(m.ttDateTime), 2) +;
  N2S(Minute(m.ttDateTime), 2) +;
  N2S(Sec(m.ttDateTime), 2) + ;
  N2S(m.tnMillisecs, 2)
My_C_Function(m.lcSysTime)

Function N2S
Lparameters tnValue, tnSize
Local lcStr, ix
lcStr = ""
For ix=1  To m.tnSize
  lcStr = m.lcStr + Chr(m.tnValue % 256)
  tnValue = Int(m.tnValue/256)
Endfor
Return m.lcStr
PS: If you've doubts try the second one and in C DLL create a function that'd accept SYSTEMTIME structure. Above code would populate the members.
typedef struct _SYSTEMTIME {
   WORD wYear;
   WORD wMonth;
   WORD wDayOfWeek;
   WORD wDay;
   WORD wHour;
   WORD wMinute;
   WORD wSecond;
   WORD wMilliseconds;
} SYSTEMTIME;
MFC Ctime class has a constructor accepting SYSTEMTIME.

PS: If C DLL function is expecting a struct you 'pack' the values in a string in foxpro and pass it. With first code on your C side it might be:
typedef struct _FOXPRODATETIME {
   DWORD date;
   DWORD nanoseconds;
} _FOXPRODATETIME;

public void my_custom_dll_function( CONST _FOXPRODATETIME *dt )
{
  // After foxpro calls this function
/*
 k = datetime()
 cDateTime = Date2Str(m.k) 
  my_custom_dll_function(m.cDateTime)
*/
  // dt.date member - has the date as a Julian day number
  // dt.nanoseconds - member has time as seconds*1000 
  // from midnight
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform