Just show the year (1 Viewer)

guihualinux

New member
Local time
Today, 05:55
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.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:55
Joined
Feb 28, 2001
Messages
27,302
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?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 04:55
Joined
Feb 19, 2013
Messages
16,658
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
 

guihualinux

New member
Local time
Today, 05:55
Joined
Feb 14, 2022
Messages
8
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
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:55
Joined
Feb 28, 2001
Messages
27,302
Then your only viable choice is the formatting properties of that field. See also CJ London's suggestions.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:55
Joined
Feb 19, 2002
Messages
43,445
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.
 

guihualinux

New member
Local time
Today, 05:55
Joined
Feb 14, 2022
Messages
8
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

Top Bottom