Forum Discussion
Luuk_Hessing
May 18, 2021Copper Contributor
Formatting 2-digit year in MS Access. How?
I need a 2-digit year notation and a 2-digit month notation from a date field.
Using the helppage of Ms Access the 2-digit month notation wasn't much of a problem after "mm" behind notation and using the magic button.
The 2-digit year notation is my problem. The instructions on the helppage didn't give the required result. Each and every attemp resulted in a 4-digit year notation.
In the setup of Windows10 I have changed the short time notation from "dd-mm-yyyy" into "dd-mm-yy" (this is the European sequence). After that I restarted my PC. The PC gives "dd-mm-yy" for short time notation.
However in MS Access the short notation remains "dd-mm-yyyy".
What an I doing wrong? How can I get a 2-digit year notation?
I'm using Microsoft365.
Regards.
- Hello Gustav,
And that was the way to do it. The option you referred to, I didn't realize that it was existing. Thank you very much.
Regards from the Netherlands.
- Gustav_BrockIron Contributor
Go to menu Files, then Settings, select Client Settings, scroll down to section General, and uncheck marks for "Use four-digit formatting of years".
- Meredith MarrCopper Contributor
Gustav_Brock I don't know if this will be seen or not. I did a Google search for this very subject and came across this thread. The problem that I'm facing is that the boxes for four-digit year formatting are ALREADY UNCHECKED. However, my database continues to apply four-digit years to some of my fields. Not all of them, but only some of them. I would very much prefer a two-digit year, but ultimately I want consistency and for some reason it is giving me four digits for birth years in the 1930's and 1940's and two digits for all birth years since 1950. Any ideas why?
- Gustav_BrockIron Contributor
Access assumes that two-digit years before 50 belong to 2000 while those 50 and after belong to 1900:
? DateValue("49-01-01") 2049-01-01 ? DateValue("50-01-01") 1950-01-01
- Luuk_HessingCopper ContributorHello Gustav,
And that was the way to do it. The option you referred to, I didn't realize that it was existing. Thank you very much.
Regards from the Netherlands.- George_HepworthSilver ContributorMy apologies. I did not realize you wanted to make this a universal setting throughout all of your accdbs.
- George_HepworthSilver Contributor
Keeping in mind that what you are talking about is a FORMAT FOR DISPLAY PURPOSES, and not the actual DATE VALUE STORED, you can do this with a Format() expression wherever you need to DISPLAY that FORMATTED STRING.
Format(Month(Date), "mm") & "/" & Format(Year(Date),"yy")
or
Format(Month(Date), "mm") & "-" & Format(Year(Date),"yy")
Having done this, you are DISPLAYING a string, not a date, so beware of trying to use it for any further date logic.
- Luuk_HessingCopper ContributorThank you for the above information.
I still wander why it is possible to get the 2-digit month number but not the 2-digit year number.
As I wrote before the 2-digit month number wasn't a problem within Access; it's the 2-digit year that keeps on showing up as a 4-digit number. Why?- George_HepworthSilver ContributorI should have been more clear. The year is a 4-digit value. To DISPLAY it as a 2 digit number, you apply the appropriate format to it.
- Luuk_HessingCopper Contributor
I was not aware how Access is storing its date/time. Thank you for this explication.
Please, also read my other reply.
- George_HepworthSilver Contributor
This is such a common request that I feel it's useful to jabber on about it a bit more.
Access ALWAYS stores dates internally as a full date and time. It does so in the form of a double.
The part of the double to the left of the decimal is the number of elapsed days since the starting date for Access dates, which is December 30, 1899 (or 12/30/1899 in the US format used by Access be default)
The part of the double to the right of the decimal is the elapsed time since midnight of the date specified. For example, 8:00AM is 8 hours after midnight, or 8/24th of a day, or 1/3 of a day, or .3333
So the current date and time might be 44334.3333 representing 8:00 o'clock in the morning on the 18th of May, 2021.
Note that in my example, I actually used several different FORMATS to express dates and times. We, humans, have learned to interpret a number of DATE FORMATS so we just do it without thinking.The important point is that no matter how the date and time are expressed, the underlying value is what Access actually stores in the table. And it stores that value as I explain above.
So, when working with dates and times in a relational database application, be careful not to confuse the ability to FORMAT a date for DISPLAY with the actual value it represents.