Calculating the day of the year

  • Thread starter Thread starter Rob Berkers
  • Start date Start date
R

Rob Berkers

Hello everybody,

Can anybody tell me how I determine in Access 2000 the day of the year
(so as a number for 1 to 366).

Thanks in advance,

Rob.
 
Rob Berkers said:
Hello everybody,

Can anybody tell me how I determine in Access 2000 the day of the year
(so as a number for 1 to 366).

Thanks in advance,

Rob.

Here's one way:

datediff("d",DateSerial(Year(Date()),1,1),Date()) + 1
 
Rob said:
Hello everybody,

Can anybody tell me how I determine in Access 2000 the day of the year
(so as a number for 1 to 366).

Thanks in advance,

Rob.

Weird... the code that I found in MS Access Help to call DateSerial()
contained a bug -- it was missing a minus sign. Anyway, what you
probably want to do is something like this SQL:

SELECT #9/3/2005# AS MyDate,
DateValue([MyDate])-DateValue("12/31/2004") AS [Day]
...

and it displays a value of 246. In VBA it would be similar to the SQL,
but you'd use variables instead of fields. You'll have to compute the
#9/3/2005# part, of course, and there are various functions in Access to
do that, including DateSerial(). Choose whichever function best fits
what data you have.

-- Vincent Johns <[email protected]>
Please feel free to quote anything I say here.
 
DatePart("y", MyDate)

For instance, to get today's day of the year:

?DatePart("y", Date())
276
 
Back
Top