This topic is locked
[SOLVED]

 Default date field

2/20/2011 4:23:24 PM
PHPRunner General questions
A
Athlon author

I have searched all over the forum and can not find a solution to what i think is a really simple task.
I have a date field entered by the user.
All i need is to make the default of another date field on the same form update automatically on the fly with the original entered date field +30 days.
I have tried all kinds of variations and can not get this to work using either sql or java. i am new to both. It would ideally be in the default value for the second date field. I can make this field a date +30 from todays date but can not reference my initial date field here ?
Any help would be gladly recieved. Sorry if it has been asked before, every example i have found reference the now() which is easy.
Thanks,
Mike

Sergey Kornilov admin 2/20/2011

Mike,
you can use BeforeAdd event and the following code:

$values["SecondDateField"] = date("Y-m-d",strtotime("+30 days",strtotime($values["FirstDateField"])));
A
Athlon author 2/21/2011

Thank you,
Worked first time.. and such a quick response.
Much appreciated.

V
Vienna 2/22/2011

Sergey,
I am wondering after seeing this code what would you suggest to trigger a "reminder" email when a date field in a record is now 7 days in the future?
That is, a details record has a field that holds "2011-04-09" indicating when an event is scheduled. When the record was first created an email was sent from events.
What is the most foolproof way to set a chron script at the server so that every day, say, just after midnight at the server, it checks this table and looks up records containing values in this field. It compares the date until it sees that the server date is 7 days from the field date next week. It then triggers an email script written in the events.php for that record.
>

Thank you,
Worked first time.. and such a quick response.
Much appreciated.

Sergey Kornilov admin 2/22/2011

Here is the article that explains how to create email script that called on timely fashion:

http://www.asprunner.com/forums/topic/14793-sample-script-to-send-email-on-timely-fashion/
This is needs to be a separate PHP file.