Board index » cppbuilder » Reccuring Date (no Year specified)

Reccuring Date (no Year specified)


2007-02-11 11:07:16 PM
cppbuilder23
Hi,
I need to let the user assign a recuuring date (such as Birthday, Anniversary, etc.) to each record in a Table
I let the user enter the month and the day using ComboBoxes (1 to 12) and (1 to 31)
However, when I try to save this date WITHOUT a year, I get an Invalid argument
Word Day, Month;
Month=5;
Day=14;
TDate Birthday = EncodeDate(0, Month, Day); //if I use Year, everything works fine
Edit5->Text=Birthday;
Is there a way to save a date in a Table field (set as Date) where only the month and the day are used?
Thanks
Rob
 
 

Re:Reccuring Date (no Year specified)

"rob kemp" < XXXX@XXXXX.COM >wrote in message
Quote
when I try to save this date WITHOUT a year, I get an Invalid
argument
If you read the documentation for EncodeDate(), you will see the
following statement:
"The year must be between 1 and 9999."
If you then look at the documentation for TDateTime (which TDate is
just a typedef of), then you will see that it can't really hold a null
year to begin with.
Quote
Edit5->Text=Birthday;
Such a statement will always display the year as well. To omit the
year, use the FormatString() method, ie:
Edit5->Text = Birthday.FormatString("mm/dd");
Quote
Is there a way to save a date in a Table field (set as Date) where
only
the month and the day are used?
Not really. Why not just store the current year when the record is
created/updated, and then ignore the year when performing operations
on the date value?
Alternatively, you can store the month/day in a smallint or integer
field instead of a date field. You can use bitwise operators to stuff
the two values together, ie:
BYTE Month = 5;
BYTE Day = 14;
WORD value = (((WORD)(Month << 8)) | Day);
// store value as needed ...
// read value as needed ...
Month = ((BYTE)((value>>8) & 0x00FF));
Day = ((BYTE)(value & 0x00FF));
Or:
WORD Month = 5;
WORD Day = 14;
DWORD value = MAKELONG(Month, Day);
// store value as needed ...
// read value as needed ...
Month = LOWORD(value);
Day = HIWORD(value);
Gambit
 

Re:Reccuring Date (no Year specified)

Remy Lebeau (TeamB) wrote:
Quote
"rob kemp" < XXXX@XXXXX.COM >wrote in message
news:45cf3124$ XXXX@XXXXX.COM ...

>when I try to save this date WITHOUT a year, I get an Invalid
argument

If you read the documentation for EncodeDate(), you will see the
following statement:

"The year must be between 1 and 9999."
This looks like it could be used to differentiate between one time
events and recurrent ones. How many of use are going to live until the
year 9999? :)
Quote

If you then look at the documentation for TDateTime (which TDate is
just a typedef of), then you will see that it can't really hold a null
year to begin with.

>Edit5->Text=Birthday;

Such a statement will always display the year as well. To omit the
year, use the FormatString() method, ie:

Edit5->Text = Birthday.FormatString("mm/dd");

>Is there a way to save a date in a Table field (set as Date) where
only
>the month and the day are used?

Not really. Why not just store the current year when the record is
created/updated, and then ignore the year when performing operations
on the date value?

Alternatively, you can store the month/day in a smallint or integer
field instead of a date field. You can use bitwise operators to stuff
the two values together, ie:

BYTE Month = 5;
BYTE Day = 14;
WORD value = (((WORD)(Month << 8)) | Day);
// store value as needed ...

// read value as needed ...
Month = ((BYTE)((value>>8) & 0x00FF));
Day = ((BYTE)(value & 0x00FF));

Or:

WORD Month = 5;
WORD Day = 14;
DWORD value = MAKELONG(Month, Day);
// store value as needed ...

// read value as needed ...
Month = LOWORD(value);
Day = HIWORD(value);


Gambit


 

{smallsort}

Re:Reccuring Date (no Year specified)

DreamChaser < XXXX@XXXXX.COM >wrote:
Quote

Please trim your posts.
Thanks!
~ JD