CDateTimeCtrl::SetFormat 

Sets the display of a date and time picker control based on a given format string.


BOOL SetFormat(
   LPCTSTR pstrFormat 
);

Parameters

pstrFormat

A pointer to a zero-terminated format string that defines the desired display. Setting this parameter to NULL will reset the control to the default format string for the current style.

Nonzero if successful; otherwise 0.

NoteNote

User input does not determine success or failure for this call.

This member function implements the behavior of the Win32 message DTM_SETFORMAT, as described in the Platform SDK.

void CDatesDlg::OnButton2() 
{
   // Gain a pointer to the control
   CDateTimeCtrl* pCtrl = (CDateTimeCtrl*) GetDlgItem(IDC_DATETIMEPICKER1);
   ASSERT(pCtrl != NULL);

   // The control will create itself with a format that matches the 
   // locale setting in Control Panel. But we can force a particular 
   // format with a call to SetFormat(). This call forces the format 
   // dd-MMM-yy, which would show 03-APR-98 for April 3rd, 1998.

   pCtrl->SetFormat(_T("dd-MMM-yy"));
}

Community Additions

ADD
Show: