Data Type

R

Reen

What would I put in the data type to make my date month and year instead of
month date and year?
 
J

Jerry Whittle

You still use the Date data type. However you format it in the table, form,
or report, to display the date as you want.

Keep in mind that SQL often doesn't play nice with DD/MM/YYYY dates that
most of the world uses.
 
K

ken

It really depends on whether you want to merely see the dates as April
2009, May 2009 etc, but still retain the ability to do date arithmetic
on the values. If you use a date/time data type you can still input
the date as May 2009, 2009 May or 2009/5, and it will be saved as 1
May 2009. You can them do date arithmetic on it so long as you bear
in mind that each date is in fact the first of the month in question.
This won't matter if doing something like getting the difference in
months between two dates using the DateDiff function for instance. To
see it as the month and year you simply format it as "mmmm yyyy"

The other option would be to use separate columns (fields) for the
year and month, but don't call the fields Year or Month as these are
the names of built in functions; use something specific like
TransactionYear. If you want to enter the month as a string make the
column a text data type, if a number use an integer number data type,
For the year use an integer number type.

You could use a single column for both year and month, of text data
type, but you'd then have to parse the value if you want to extract
the year only for instance, so two columns are a better bet.

If you do use separate columns you can still do date arithmetic but
you'll first have to convert the values to a date/time value, which
again would become the 1st of the month with an expression such as:

CDate([TransactionYear] & "/" & [TransactionMonth])

Ken Sheridan
Stafford, England
 
J

John W. Vinson

What would I put in the data type to make my date month and year instead of
month date and year?

Don't confuse data PRESENTATION with data STORAGE.

A Date/Time field isn't stored as either d/m/y or as m/d/y; it's actually
stored internally as a double float count of days and fractions of a day since
midnight, December 30, 1899:

?now & " " & cdbl(now)
5/12/2009 12:49:16 PM 39945.534212963

You and *DISPLAY* the date/time value with any format that you choose. The
builtin "Short Date" and "Long Date" formats will reflect whatever format you
have chosen in the Start... Control Panel... Regional and Language settings on
Windows, or you can use home made formats such as mm/dd/yyyy or dd/mm/yyyy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top