+ Start a Discussion
Joanna KirkJoanna Kirk 

How do I create a field for 'year' (with a validation rule that it cannot be in the future)?

e.g. trading since (year)

I've been told to start with a number field (4 digit limit) but need a hint on where to start with the sytax! Any help appreciated.
Best Answer chosen by Joanna Kirk
Shyama B SShyama B S
So, you want to add a length check also right? You can do that like this:
IF(Value(Year__c) > Year(TODAY()),true,IF(LEN(Year__c)=4,false,true))

All Answers

Joanna KirkJoanna Kirk
*syntax
Shyama B SShyama B S
Hi Joanna,
You can create avalidation rule with the below formula,
IF(Year__c > Year(TODAY()),true,false)

Where Year__c is a custom field of number type and is chakced against the year of today. Please let me know if this helped you.
Thanks,
Shyama
Joanna KirkJoanna Kirk
Hi Shyama, thank you - Much apppreciated!

The number displays with a comma, e.g. '2,015' - Is there any way to show this differently?
If not, should I change the data type to something else? 
 
Shyama B SShyama B S
Yes. You can change it to a text field. And update the formula like the below:
IF(Value(Year__c) > Year(TODAY()),true,false)

Thanks
Shyama B SShyama B S
And please mark the answer as the best answer if it helped you. Thanks!
Joanna KirkJoanna Kirk
That looks good! One last thing, the field itself is not mandatory, but I need to make sure if the users enter the year, it is done properly:

so all 4 digits, say, starting from 1300 to Year(TODAY ())  .

I'm not sure if I'm going in the right direction, but think I need to include some of the followng elements somehow: AND IF (Value(Year__c) == 4, true, false)
Shyama B SShyama B S
So, you want to add a length check also right? You can do that like this:
IF(Value(Year__c) > Year(TODAY()),true,IF(LEN(Year__c)=4,false,true))
This was selected as the best answer
Joanna KirkJoanna Kirk
Great, that works well. Flagged as best answer.
Thanks and have a great day Shyama.
Shyama B SShyama B S
Glad it worked.