Objective Grid: Default date for custom date formats

Article ID: 282
Last updated: 11 Jun, 2018
Article ID: 282
Last updated: 11 Jun, 2018
Revision: 3
Views: 1926
Posted: 23 Jan, 2001
by Meltreger B.
Updated: 11 Jun, 2018
by Meltreger B.

Problem


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.


Cause



Action


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
// 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);
else
{
COleDateTime d = COleDateTime::GetCurrentTime();
dt.SetDate(d.GetYear(), d.GetMonth(), d.GetDay());
}
}

SetDateTime(dt);
OnModifyCell();

}
}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 282
Last updated: 11 Jun, 2018
Revision: 3
Views: 1926
Posted: 23 Jan, 2001 by Meltreger B.
Updated: 11 Jun, 2018 by Meltreger B.

Others in this category