3069 Posts in 868 Topics by 650 members
| Go to End | Next > | |
| Author | Topic: | 1798 Views |
-
Week

28 March 2009 at 10:43am
I have a an event table SeminarPage with the date saved in format YYYY-MM-DD
If I want to select events of today I simply
$today=date('Y-m-d');
$results = DataObject::get("SeminarPage","`seminardate`='$today'");===
Now I want to select this week
$thisweek=date('-W');
$results = DataObject::get("SeminarPage"," ....='$thisweek'");My problem is that seminarweek is not stored in the table and should be calculated as a function of `seminardate`:
seminarweek=date('-W','`seminardate`);I am not sure how insert this calculation into clause .
Thank you in advance
Victor
-
Re: Week

1 April 2009 at 12:02am
you can get the date from the dataobject which you create and add 7 days to it, and try to work with time epochs it will be the best,
Sometimes you can make use of my diary module. http://silverstripe.org/diary-module/
-
Re: Week

1 April 2009 at 12:19am
Thanks. I have the same idea but I am stuck. Probably eventually I will find the script which takes date in 2009-03-31 format and determines the week. Right now we put it manually
BTW week in CalendarDateField selector is shown differently than date('W') returns (probably because in NZ it is counted differently).
However there is another, more deep question. Assume that I want to store in database some function of of other fields: f.e. I have lastname, firstname and fullname which should be "firstname lastname". How to create CustomPage.php which creates an entry form for firstname and lastname but enters fullname automatically (this example is obviously artificial).
Thanks. Victor
-
Re: Week

1 April 2009 at 2:27am
You might be able to do this in onBeforeWrite().
Your data object could have a field for your "computed" type. You would compute the and set the field's value in onBeforeWrite().
-
Re: Week

1 April 2009 at 2:35am
Thanks. Should be in this example be
function onBeforeWrite() {
$fullname="$firstname $lastname"
}
{/code]Victor
-
Re: Week

1 April 2009 at 2:37am
Off the top of my head, I think it would be like (but I haven't tried it):
function onBeforeWrite() {
$this->fullname = $this->firstname . ' ' . $this->lastname;
parent::onBeforeWrite();
} -
Re: Week

1 April 2009 at 2:44am
Thanks! Now I need to find out the calculation needed to find the Week Number from date.
Victor
-
Re: Week

1 April 2009 at 3:59am Last edited: 1 April 2009 4:48am
In forms
$thisdate=$_POST['seminardate'];
echo strftime("%Y-%V-%u", strtotime($seminardate))
this works fine; butfunction onBeforeWerite(){
$this->seminarweek = strftime("%Y-%V-%u", strtotime($this->seminardate));
}
reports javascript error
| 1798 Views | ||
| Go to Top | Next > |



