webtotaltoday
Posts: 46
|
Posted: 04/30/2007, 5:17 AM |
|
Hello,
I have the following code:
$DATE = $T_Tenancy->enddate->GetValue();
$SQL = "INSERT INTO reminders VALUES ($stamp,'Property Inspection','3 Month Property Inspection',$DATE,'No',$value)";
$db->query($SQL);
$db->close();
Now what i need to work out is the end date minus a month, i can insert the enddate straight in to the database fine, but cant get it to minus a month off first.
please help thanks
|
|
|
Wkempees
|
Posted: 05/01/2007, 5:15 AM |
|
Use
CCDateAdd() a CCS function in Common.php
To be used in your event source.
CCDateAdd( $date, $ value )
$date must be a valid and properly formatted date.
$value indicates the addition to be made.
$value can be a positive or negative number followed by a period
indicator, in your case it would be "-1 month"
So in "On Validate event",
$Component->SetValue( CCDateAdd( $Component->GetValue(), "-1 month") );
would set back the month by one.
"-30 days" would be an option too, if you want it that way.
Disclaimer:
I am not telling you to do it in On Validate, it is merely a good way to
see the result on the form.
Walter
|
|
|
webtotaltoday
Posts: 46
|
Posted: 05/01/2007, 5:46 AM |
|
Thanks Walter,
Thanks for that.
For some reason it wont insert in to the database:
Here is the code now:
$date1 = $T_Tenancy->enddate->GetValue();
$str1 = date("d/m/Y", strtotime($date1));
$date2 = CCDateAdd( $str1, "-1 month");
$SQL = "INSERT INTO reminders VALUES ($stamp,'Property Inspection','3 Month Property Inspection',$date2,'No',$value)";
$db->query($SQL);
$db->close();
|
|
|
webtotaltoday
Posts: 46
|
Posted: 05/01/2007, 5:47 AM |
|
Also,
When the date is picked up it is in US format eg mm/dd/yyyy
hence the code
$str1 = date("d/m/Y", strtotime($date1));
to try and covert it to UK dd/mm/yyyy
|
|
|
Wkempees
|
Posted: 05/01/2007, 6:21 AM |
|
echo all the variables and the SQL to see what goes and what doesn't.
$date1 = $T_Tenancy->enddate->GetValue();
$str1 = date("d/m/Y", strtotime($date1));
$date2 = CCDateAdd( $str1, "-1 month");
echo ( "date's are: ". $date1 . " - " . $str1 . " - " . $date2 );
$db->Debug = True; // add this line and your Browser will
display the SQL generated, visualy check it or feed it to the
database using your SQL CLI, later just comment the line out
$SQL = "INSERT INTO reminders VALUES ($stamp,'Property Inspection','3 Month
Property Inspection',$date2,'No',$value)";
$db->query($SQL);
$db->close();
|
|
|
|