Date/Time formatting in Items.Restrict (in C++)

  • Thread starter Thread starter Mattias
  • Start date Start date
M

Mattias

I have a problem with the usage of the Restrict function in C++. I want
to use a query like "[Start] >= '1/1/2005 00:00'" but the problem is
that the date and times must be specified using the correct locale. The
time part is important since Outlook otherwize use the "start of
working day" for the time part. But I also want to include the all day
events for that day!!!

In the Microsoft Office VBA documentation they suggest that the Visual
Basic function FormatDateTime is used, but this function doesn't exist
in C++. I mostly use the MFC COleDateTime for my date work. The date
part is no problem. I just use:

COleDateTime dtDate(2005, 1, 1, 0, 0, 0);
CString strDatePart = dtDate.Format(VAR_DATEVALUEONLY);

But for the time part I cannot use the VAR_TIMEVALUEONLY since the
seconds are used there as well.

How should I format the time part??? I've tried to just append _T("
00:00") to the date but that only work using some locales. I suspect
that AM/PM parts must be used sometimes (12/24 hour clocks????)
 
Mattias said:
But for the time part I cannot use the VAR_TIMEVALUEONLY since the
seconds are used there as well.

How should I format the time part???

I'm not sure exactly what Outlook is doing here, but COleDateTime.Format
("%c") gives you the date and time formatted the "local" way. See the docs
for strftime for more options, Format uses the same stuff as strftime; %
x/%X are date/time for the current locale. You might have to strip the
seconds part off with string manipulation, I'm not sure how picky Outlook
is. (I know that CDO1.21 will only filter to the nearest minute, it just
ignores any seconds you pass in)

-- dan
 
Ok, so I need to check the time separator / time format for the current
locale and then remove the seconds part. That doesn't sound that easy
regarding all different time formats for all different locales.

Isn't there really another way to do this in C++? How is the time part
formatted in VB? Isn't the same possible in C++?
 
Mattias said:
Ok, so I need to check the time separator / time format for the current
locale and then remove the seconds part. That doesn't sound that easy
regarding all different time formats for all different locales.

That does sound messy, but you can presumably just get the seconds part
of the time and then search for that in the string and remove it and the
previous character -- I don't think it's likely that any national time
formatting will put seconds anywhere other than at the end of the string
for time-of-day.
Isn't there really another way to do this in C++? How is the time part
formatted in VB? Isn't the same possible in C++?

I'm sure it must be possible somehow, but I don't know how myself,
sorry, all I can suggest is looking in the documentation some more.

I'd try asking in microsoft.public.win32.programmer.international, given
that your problem is now down to just one of how to format a time in the
right sort of internationalised way.

-- dan
 
Back
Top