Is Unique build rule to check uniqueness on year only not whole datetime field ? - cakephp-3.0

I want to validate combination of email and created using build rules such that created field's year is considered only for uniqueness.
$rules->add($rules->isUnique(['email', 'created'], 'invalid entry'));

Seems like you need to do custom validation

Related

How to calculate the difference between days in a table field

Ok this should be a relatively easy thing to do, yet I'm at the head desk stage trying to figure out the insanity here.
I have a table called tblPersonnel. I'm tracking two document expiration dates in date/time fields called CED and PPED. When I run a query against tblPersonnel I need it to look at PPED, determine if that document is expired and if so use CED instead. I have a few fields in the query that need to use this concept to determine what the output value is, but I am hitting a wall here trying to get the query to spit out the correct value. Here's what I'm using for one of the fields - Document Expiration Date: IIf([PPED]-Now()<0,[CED],[PPED]). What's happening is that the expression is constantly popping as false, so PPED is getting used regardless if it's an expired date or not. Does anyone have any ideas as to what I'm doing wrong here?
I've also tried to set this up as its own field in tblPersonnel, but that's even more aggravating. If I try to set the field to just a text field - IIf([PPED]-Now()<0,"Yes","No"), the formula will accept the use of Now(), but it doesn't like the reference to the other fields in the table. If I set it as a calcuated column, I can reference the other fields but it doesn't like Now(). I'm at a loss here.
If PPED is less than Date(), it is expired. Don't need to subtract. Assuming CED and PPED are just date parts, no time, consider:
IIf([PPED] < Date(), [CED], [PPED])
If PPED could be null:
IIf(Nz([PPED],0) < Date(), [CED], [PPED])
Ok finally fixed it here. I had another issue in that I wasn't accounting for how Access would handle a Null or blank value in PPED. The functioning formula is Document Expiration Date: IIf(Len([PPED])>0,IIf([PPED]<Date(),[CED],[PPED]),[CED]) Thanks to June7 for helping me simplify the expression, as I was using DateDiff('d',[PPED],Date())<0 but their answer is just so much cleaner and quicker to type.

Error in Expression used for Control Source in an Access Form

I actually have two questions.
I'm a beginner user of Access, still trying to get a good understanding of the software. I'm trying to create a database for a library (School project) with a borrowing out system. I have two fields in a table called DueDate and DateHired. The DueDate functions on the expression =Now()+28 and the DateHired function on the expression =Now(). Basically making the due date 4 weeks ahead of when the book was hired. My first question is quite simple; if I were to input a record today, would the two DueDate/DateHired fields remain the same date and time by tomorrow? Or would they update to the Now() of tomorrow?
My second question is something regarding an expression. I'm trying to make an Overdue checkbox. The premise is that if Now()>DateDue then the Checkbox will be 'Yes'. My current code in the ControlSource part is this:
=CBool([DateDue]
However, the checkbox simply displays '#Error' and not Yes/No. I'm also concerned that if the answer to the first question was '=Now() stays the same after the record is added and doesn't update' that would also mean the Overdue function would not really work unless you were inputting the record after the due date. Which would make no sense. Any suggestions?
Cheers.
This is relation to your second question. You can ask a separate question for the first part.
=CBool([DateDue]
What you are trying to do here, is convert a Date data type to a Boolean (you're missing the closing parentheses by the way) which is impossible.
What you should be doing is check if the due date is less than today and return the appropriate True/False value.
IIf([DueDate] < Date(), True, False)
Which means:
IIf("Is due date in the past?", "Yes, it's overdue", "No, it's not overdue")
You can read more about the IIf function here.
Indeed as a beginner, make it a habit to use the date functions. Later you can turn to "smarter" methods which, by the way, often aren't that smart.
1.
If you store a date, it remains unchanged in the table. And don't use Now unless you specifically need the hours too:
DateDue = DateAdd("d", 28, DateHired)
or in a query - using the designer:
DateDue: DateAdd("d",28,[DateHired])
or as a ControlSource for a textbox on your form:
=DateAdd("d",28,[DateHired])
2.
You can use DateDiff for this:
Due = DateDiff("d", DateHired, Date) > 28
or in a query - using the designer:
Due: DateDiff("d",[DateHired],Date()) > 28
or as a ControlSource for a textbox on your form:
=DateDiff("d",[DateHired],Date()) > 28
and set the Format property of the textbox to, say, Yes/No or something else meaningful for your users.

Howcan I change the visible name of a many2many field?

I am using Odoo8.
I have two models: x_items and project.task.work.
I have a field called name and a custom field called x_wo_ref in the project.task.work.
I have a many2many field x_item_wo in the model x_items which is related with the model project.task.work.
Currently when I fill the field x_item_wo, the field name from project.task.work is showed.
How can I customise it in order to use the field x_wo_ref instead of the default field name for this many2many field?
Thank you
You need to define the _rec_name attribute of the model. _rec_name takes as default the field name and if this does not exist it does not take anything unless you specify it. For instance if you need to see the field phone you must write:
_rec_name = 'phone'
In case you want a _rec_name depending on anything you need to change the function name_get(). You can see examples in other models.

What is the convention value for a Date to set as default?

I am parsing some json data that has a date element, and sometimes its value can be null. My application needs to be able to handle nulls, therefore I have to set the date value to a default value, so I am not sure if there is a convention / rule that I should be following? Any help is appreciated!
If you get null where you expect a date, that means whoever created the data intentionally gave you a null value. You shouldn't even think about using some default date. You should store the information that no date was provided. A null value is even stronger than a missing key/value pair in a dictionary.

Assigning a default value to a Microsoft Access Table Field?

I have a database table in Microsoft Access. I want to assign the default value of one of those fields to another field that happens earlier in the same table.
I tried the value =[Form1].[AssignedByes] with no luck and the same for =[AssignedByes] but with no luck.
Can anyone help?
The field name I'm assigning the value to is [RemainingByes] and the field that assigning the value of is [AssignedByes].
To get around this problem, I create a Query that basically functions as the table. I use it instead of the table when creating other queries, forms, etc.
I'm guessing that you copy [AssignedByes] into [RemainingByes], because [RemainingByes] will start off with the value of [AssignedByes], but you want to be able to change it later.
So, you can set up the Query with a calcualted field called [xRemaningByes]. You would enter the changed values in [RemainingByes]. Then set up a formulat in [xRemainingByes] that returns the value of [RemainingByes] if there is one, and it not, it returns the value of [AssignedByes].
[xRemainingByes]: Iif([IsNull([RemainingByes],[AssignedByes], [RemainingByes].
When you use the Query instead of the Table, you will use [xRemainingByes], which is the Query's calculated field, instead of the Table's field [RemainingByes].
ANOTHER OPTION ---
Create a field in the Table such as [RemainingByesOverride], and that would be where you hard enter the changing data. Then get rid of [RemainingByes] in the table and only have it in the Query as a calculated field.
[xRemainingByes]: Iif([IsNull([RemainingByesOverride],[AssignedByes], [RemainingByesOverride]
A field's default value is applied at the instant a new record is created. So you can't use [AssignedByes] as the default value for [RemainingByes], because [AssignedByes] doesn't have a value yet.
OTOH, if you've assigned a default value property for [AssignedByes], use that same property for [RemainingByes].
If your Access version is 2010, see whether you can use a data macro as a pseudo-trigger to accomplish what you want.
You could also try binding a form to the table. In the after update event of the control bound to [AssignedByes], you can assign a value to another control bound to [RemainingByes]. This could allow you to do what you need in the form, but won't apply for changes made outside the form.