VC/MFC time format conversion and comparison size CString to COleDateTime

Source: Internet
Author: User

It's been a long time. Finally, I have finished the problem of the conversion of the date format, and share my little experience here, hehe

The database I use is SQL Server2005, and there is a type of smalldatetime data in the database table to store the departure time (for example: 2010-1-1 10:00:00)

Request in VC + + to extract the time and compare with the current system time, Judge 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 re-enter!");
Return
}


Get the departure time of the shift
Cbus it;
It. GetData (M_EDITBC);
CString str1 = "";
Str1+=it. GetRuntime ();

Get System Current Time
COleDateTime;
COleDateTime datetime;
Datetime=coledatetime::getcurrenttime ();
CString Str2=datetime.  Format ("%y-%m-%d%h:%m:%s"); Set the system time format to match the time format in the database

Time format conversion compares CString to coledatetime,coledatetime type of time can be directly compared to 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)//Direct judgment size
{
MessageBox ("The shift is OFF!");
Return
}

The following code is slightly 、、、、、、

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.