Just show the year

guihualinux

New member
Local time
Today, 18:40
Joined
Feb 14, 2022
Messages
8
Hi guys.
I want it to show me only the year without having to change the data type of "Date/time".

Basically I want to transform this:
1645112771127.png


To this:
1645112813912.png


But I get an error when I don´t put the month and day.
 
Are you saying you want to ONLY enter the year? Or that you will enter a full date but only want to SHOW the year?

The "only show the year" can be accomplished by changing the format of the field, such as Format( Ano, "yyyy")

If you never want to enter day or month, the question becomes "why do you need it to be a date/time data type?
 
use either the format property of the format function. Using the property will retain the underlying value, the function will provide a text result (so you can't use maths on it.

Alternatively use the datepart function to retain the value

format property yyyy
format([mydate],"yyyy")
datepart("yyyy",[myDate])

All depends an what you are going to do with it
 
Are you saying you want to ONLY enter the year? Or that you will enter a full date but only want to SHOW the year?

The "only show the year" can be accomplished by changing the format of the field, such as Format( Ano, "yyyy")

If you never want to enter day or month, the question becomes "why do you need it to be a date/time data type?
I want keep the date/time data type for queries of search between 2 years
 
Then your only viable choice is the formatting properties of that field. See also CJ London's suggestions.
 
the problem with keeping the year as a datetime data type is that you will have to enter month/day as well. I would store just the year and then format the year into a datetime for use in queries.
 
use either the format property of the format function. Using the property will retain the underlying value, the function will provide a text result (so you can't use maths on it.

Alternatively use the datepart function to retain the value

format property yyyy
format([mydate],"yyyy")
datepart("yyyy",[myDate])

All depends an what you are going to do with it
It worked. It was just what I wanted.
Thank you so much.
 

Users who are viewing this thread

Back
Top Bottom