Convert VC/mfc time format and compare the size cstring to coledatetime

Source: Internet
Author: User

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 ,,,,,,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.