|| | |||Browse by category|
Why does the DateTime control use 12/30/1899 as the default date when I use a custom format? I would like to have the initial value of the control be the current date and time.
We are setting it to this date because this is the "PSEUDO NULL" date for COleDataTime.
With this date, it will only save the time if you don't need to specify date but only time. If we would set it to the today's date, the date would always be saved even if you only want to have time values.
What you could do to change the behavior is subclass CGXDateTimeCtrl and override the SetValue() method as follows. Then it should be fine.
|void CMyDateTimeCtrl::SetValue(LPCTSTR pszRawValue)
|// Convert the value to the text which should be
// displayed in the current cell and show this
if (pszRawValue == NULL || !dt.ParseDateTime(pszRawValue))
|if (pszRawValue != NULL && _tcslen(pszRawValue) > 0 && _gxttof(pszRawValue) != 0)|
|dt = _gxttof(pszRawValue);|
|// the following two lines are
// commented out so that the
// initial date for custom format
// is the current date
// else if (m_formatType == Custom)
|// Set date to zero date - 12/30/1899
// dt.SetDateTime(1899, 12, 30, 0, 0, 0);
|else if (m_formatType == Time)|
|dt.SetTime(0, 0, 0);|
|COleDateTime d = COleDateTime::GetCurrentTime();
dt.SetDate(d.GetYear(), d.GetMonth(), d.GetDay());