LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DateTimePicker control problems

Hi all,
I'm using the DateTimePicker control (from Microsoft Common Control - Mscomct2.ocx) in CVI 6.0.

I have two problems:

1. I programmatically set the MinDate property with the command
err = MSComCtl2_IDTPickerSetMinDate (ini, NULL, va_date);
Next when I set the MaxDate property in the same manner the control behaves as the MinDate property has been reset (i.e. I can input dates before the MinDate value I entered)

2. I must compare the value from this control with a value recorded on a file in the dd/mm/yyyy format in order to select records from the file: I would like to avoid the elementary control on day/month/year values and so I tried to convert the date read from a file in a number and confront it with the Value property from the control. The problem is that I'm not be able to obtain the same result in C and from the control.
I tried to use the mktime() function and use the control's value, but with the same date of January 20th, 2002 I find different numeric values returned from the two functions. Here is my code:

struct tm dh;
VARIANT var;
DATE va_date;

// msg is "29/01/2002"
// ANSI C calculation
Scan (msg, "%d[x]%d[x]%d", &dh.tm_mday, &dh.tm_mon, &dh.tm_year);
dh.tm_year -= 1900; dh.tm_mon--; // Adjust values according to the definition of the tm structure
va_date = (double)mktime (&dh) / 86400.0; // mktime returns nr. of seconds since jan 1, 1900, so I divide by seconds-per-day to obtain nr. of days

// Set the DateTimePicker date
Scan (msg, "%d[x]%d[x]%d", &dd, &mm, &yy);
CA_VariantSetInt (&var, dd); MSComCtl2_IDTPickerSetDay (ini, NULL, var);
CA_VariantSetInt (&var, mm); MSComCtl2_IDTPickerSetMonth (ini, NULL, var);
CA_VariantSetInt (&var, yy); MSComCtl2_IDTPickerSetYear (ini, NULL, var);
// Retrieve value from the control in Variant format
err = MSComCtl2_IDTPickerGetValue (ini, NULL, &var);
// Convert in DATE format
err = CA_VariantGetDate (&var, &va_date);

The va_date calculated in the first manner is three days before the second date obtained!!

What I'm doing wrong??

Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 1 of 1
(3,669 Views)