PDA

View Full Version : Date & Time Functions


Paul Fielder
10-20-2006, 09:03 AM
Are there any more date time functions other than in the datetime demo? In particular I'm looking for datediff or something similar. I have tried subtracting the values store within the date time struct but not received the results that I expected.

kornalius
10-20-2006, 01:05 PM
Hi Paul,

Look at DateTime.ppl library file in the Lib\ folder.

There are a few functions defined there:

#declare GetLocalTime kndll GetLocalTime 1 0
#declare GetSystemTime kndll GetSystemTime 1 0

#declare CompareFileTime kndll CompareFileTime 2 1
#declare FileTimeToSystemTime kndll FileTimeToSystemTime 2 1
#declare SystemTimeToFileTime kndll SystemTimeToFileTime 2 1
#declare FileTimeToLocalFileTime kndll FileTimeToLocalFileTime 2 1
#declare LocalFileTimeToFileTime kndll LocalFileTimeToFileTime 2 1
#declareapi GetTimeFormat kndll GetTimeFormat 6 1
#declareapi GetDateFormat kndll GetDateFormat 6 1

To compare time and date you will need to convert the system time to a file time using SystemTimeToFileTime () or LocalTimeToFileTime() and then use CompareFileTime() function.

Paul Fielder
10-21-2006, 11:17 AM
Below is my code including using LocalTimeToFileTime and CompareFileTime, I looked at MSDN but still having no luck :-(

#include "TimeDate.ppl"

Proc Main

// define the systemtime structure variable
struct(st$, SYSTEMTIME);
struct(dt$, SYSTEMTIME);
struct(rt$, SYSTEMTIME);
struct(ft1$, FILETIME);
struct(ft2$, FILETIME);

Local(Date1$, Date2$);

// Get the system time and date
GetSystemTime(&st$);

// Show some fields from the systemtime structure variable
ShowMessage(st.wDay$ + "/" + st.wMonth$ + "/" + st.wYear$ + " " + st.wHour$ + ":" + st.wMinute$ + ":" + st.wSecond$);

// Set the Exit Date
dt.wDay$ = 3;
dt.wMonth$ = 1;
dt.wYear$ = 1900;

If (SystemTimeToFileTime(&Date1$, ft1$) == 0)
ShowMessage("Faild 001");
End;
If (SystemTimeToFileTime(&Date2$, ft2$) == 0)
ShowMessage("Faild 002");
End;

/* A return value of –1 indicates that the first file time is less than the
second file time. A return value of zero indicates that the first file
time is equal to the second file time. A return value of +1 indicates
that the first file time is greater than the second file time.
*/

RetVal$ = CompareFileTime(ft1$, ft2$);

ShowMessage(RetVal$);
End;

kornalius
10-22-2006, 08:31 PM
If (SystemTimeToFileTime(st$, &ft1$) == 0)
ShowMessage("Faild 001");
End;
If (SystemTimeToFileTime(st$, &ft2$) == 0)
ShowMessage("Faild 002");
End;

This will do it. You need to convert systemtime st$ to a filetime (&ft1$ and &ft2$).

Date1$ and Date$ are simple variables, they don't have a structure.

Richard
11-03-2006, 11:07 PM
Hi Kornalius,

Just wanted to look at the Date/Time functions and found this post. I searched all my C:\Program Files\PPL folders, but I don't have a DateTime.ppl file installed anywhere.

How can I get it please? Is there a set of files that I might be missing?

Thanks, Richard.

kornalius
11-04-2006, 12:55 AM
Sorry it is called TimeDate.ppl in C:\Program Files\PPL\Runtime\Lib on the PC and \Program Files\PPL\Lib on the PocketPC.