After a long time, I finally completed the problem of time format conversion and comparison. Here I will share some of my experiences.
The database I use is SQL server2005. The database table contains smalldatetime data that is used to store the departure time (for example, 10:00:00)
It is required to extract the time in VC ++ and compare it with the current system time to determine the size.
Void csaledlg: onbtnsurebuy ()
{
// Todo: add your control notification handler code here
Updatedata (true );
M_editbc.trimleft ();
M_editbc.trimright ();
Cbus lt;
If (! Lt. ifexistid (m_editbc ))
{
MessageBox ("this shift does not exist. Please enter it again! ");
Return;
}
/// // Get the departure time of the specified shift
Cbus it;
It. getdata (m_editbc );
Cstring str1 = "";
Str1 + = it. getruntime ();
/// // Obtain the current system time
Coledatetime;
Coledatetime datetime;
Datetime = coledatetime: getcurrenttime ();
Cstring str2 = datetime. format ("% Y-% m-% d % H: % m: % s"); // set the system time format to be consistent with the time format in the database
///////////////// // The time format is converted to coledatetime, coledatetime-type time can be directly compared to the size
Coledatetime T;
T. parsedatetime (str1); // converts the cstring type time in the table to coledatetime.
Coledatetime P;
P. parsedatetime (str2); // convert the obtained system time cstring type to coledatetime
If (T <= P) // directly determine the size
{
MessageBox ("this shift has started! Unable to purchase tickets! ");
Return;
}
BelowCodeOmitted ,,,,,,