ckroon
Posts: 869
|
| Posted: 04/24/2008, 10:34 PM |
|
A school has three terms. When they enter comments in a box, I need it to look at the current date and determine which term we are in and save that value in a record.
After much struggling I managed to get the following:
Hidden fields on the record:
term-the field where the term is set
current_date- (default value is set to Current Date)
term1, term2 and term 3- (each populated with the first day of their respective terms)
All date fields are set to yyyy-mm-dd.
Above date fields are working correctly and have data.
Here is the code I have on the Before Show Event of the Record.
$Container->current_date->GetValue();
if ($Container->current_date->GetValue() >= $Container->term1->GetValue());
$Container->term->SetValue(1);
if ($Container->current_date->GetValue() >= $Container->term2->GetValue());
$Container->term->SetValue(2);
if ($Container->current_date->GetValue() >= $Container->term3->GetValue());
$Container->term->SetValue(3);
It always sets to Term 3, no matter what the dates are in the term1 term2 or term3 fields
My guess is that I need to parse the dates out but I have no idea how to do it in this instance.
Any help is greatly appreciated.
Thanks!
_________________
Walter Kempees...you are dearly missed. |
 |
 |
tonyk
Posts: 163
|
| Posted: 04/25/2008, 7:37 AM |
|
Have you set the dbformat for your date fields?
Also just a simple point, you have got the right values to compare against? How are you entering data into the term1.. term2 fields?
The standard date fields on the form are arrays. You may find it easier to convert the date fields to text fields unless entering data into the term1... fields directly from the database. You have to compare like with like, you can't compare an array to a text field.
In a mock up of your problem I had successful comparisons without changing the data type for the fields from date. I suspect you are not setting the dbformat (its at the bottom of the field descriptor in the properties for the control).
|
 |
 |
ckroon
Posts: 869
|
| Posted: 04/25/2008, 7:44 AM |
|
Hi Tony. Thanks for your response.
The term1, term2 and term3 fields are pulled from a database table with ccdlookups.
The dbformat for all these fields is set to yyyy-mm-dd.. but I will double check them to be sure.
_________________
Walter Kempees...you are dearly missed. |
 |
 |
wkempees
|
| Posted: 04/26/2008, 2:29 AM |
|
$Container->current_date->GetValue();
if ($Container->current_date->GetValue() >=
$Container->term1->GetValue());
$Container->term->SetValue(1);
if ($Container->current_date->GetValue() >=
$Container->term2->GetValue());
$Container->term->SetValue(2);
if ($Container->current_date->GetValue() >=
$Container->term3->GetValue());
$Container->term->SetValue(3);
Does not look right to me at first glance.
$Container->current_date->GetValue();
if ($Container->current_date->GetValue() >= $Container->term1->GetValue())
$Container->term->SetValue(1);
if ($Container->current_date->GetValue() >= $Container->term2->GetValue())
$Container->term->SetValue(2);
if ($Container->current_date->GetValue() >= $Container->term3->GetValue())
$Container->term->SetValue(3);
looks better, lost the colon; after each line starting with 'if '
|
|
|
 |
tonyk
Posts: 163
|
| Posted: 04/26/2008, 8:18 PM |
|
doh !
missed it
|
 |
 |