CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2022
    Posts
    1

    How to get selected value from DateTimePicker? (Visual C++ 6 MFC)

    Hello everybody! Nede some help - trying to get date from DateTimePicker, so the code is:

    m_Date.GetStatus();
    CString day;
    day.Format("%i",m_Date.GetDay());

    So variable "day" gets value "15" (today is 05-15-2022, it's correct) but I need to get selected value, for example, 05-04-2022 from this DateTimePicker - how to implement it? Thank you for answers.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to get selected value from DateTimePicker? (Visual C++ 6 MFC)

    See https://docs.microsoft.com/en-us/cpp...vc-170#gettime
    Code:
    // assuming your m_Date is of the type CDateTimeCtrl 
    COleDateTime selectedDateTime;
    if (!m_Date.GetTime(selectedDateTime))
    {
             // error
             ...
    }
    else
    {
             // success, now you can use COleDateTime::Format method to obtain the datetime value as text
             ...
    }
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured