Why does the DateTime control use 12/30/1899 as 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. (January 9, 1998)
OG 6.1: We modified the parsing routing for the custom format. If it detects and date tokens (day, month or year) the initial value will be set to current date. If the parsing finds only time tokens the initial value will be PSEUDO_NULL.
OG 6.0:
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
// text.
if (m_hWnd)
{
COleDateTime dt;
if (pszRawValue == NULL || !dt.ParseDateTime(pszRawValue))
{
if (pszRawValue != NULL && _tcslen(pszRawValue) > 0 && _gxttof(pszRawValue) != 0)
dt = _gxttof(pszRawValue);
// the following two lines are commnented 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);
else
{
COleDateTime d = COleDateTime::GetCurrentTime();
dt.SetDate(d.GetYear(), d.GetMonth(), d.GetDay());
}
}
SetDateTime(dt);
OnModifyCell();
}
}
Note: Only the full version of Objective Grid does provide a date-time control.