How to use a unix timestamp for an adDate ADO Parameter in c++ without COleDateTime
- From: peterloh@xxxxxxxxx
- Date: 18 Mar 2007 06:44:28 -0700
Just thought I'd share this because it has been bugging me for
hours...
When you're calling a SQL Server stored procedure with a DATE
parameter, this is how you can add the parameter in ADO (without the
need for COleDateTime)....
double * UnixTimestampToVariantTime(time_t unixTimestamp);
.....
dtmGenerated = UnixTimestampToVariantTime(time(NULL)); // This
converts the current unix timestamp (calculated by time(NULL)).
sqlCmdUpdateEvents->Parameters->Append(sqlCmdUpdateEvents-
CreateParameter("@TimeGenerated", (DataTypeEnum)adDBTimestamp,(ParameterDirectionEnum)adParamInput, sizeof(DATE),
(DATE)*dtmGenerated));
.....
// Converts a unix timestamp into one that ADO can decipher
double * UnixTimestampToVariantTime(time_t unixTimestamp)
{
double *dblDBTS = new double;
SYSTEMTIME dbDate;
ZeroMemory(&dbDate, sizeof(SYSTEMTIME));
// Get the tm Struct for the specified unix timestamp
struct tm *timeUnits = localtime(&unixTimestamp);
// Translate the tm struct into a SYSTEMTIME struct
dbDate.wDay = (WORD)timeUnits->tm_mday;
dbDate.wDayOfWeek = (WORD)timeUnits->tm_wday;
dbDate.wHour = (WORD)timeUnits->tm_hour;
dbDate.wMilliseconds = (WORD)0;
dbDate.wMinute = (WORD)timeUnits->tm_min;
dbDate.wMonth = (WORD)timeUnits->tm_mon+1;
dbDate.wSecond = (WORD)timeUnits->tm_sec;
dbDate.wYear = (WORD)timeUnits->tm_year+1900;
// Calculate and return the Variant time for the populated SYSTEMTIME
struct
SystemTimeToVariantTime((LPSYSTEMTIME)&dbDate, dblDBTS);
return dblDBTS;
}
.... Just snippets, but you get the idea.
.
- Prev by Date: Re: Printing a template argument as a literal string
- Next by Date: Re: GetSystemInfo
- Previous by thread: Re: Printing a template argument as a literal string
- Next by thread: Leak detection works in vs2003, not in vs2005
- Index(es):
Relevant Pages
|