Current Year help

steve711

Registered User.
Local time
Yesterday, 22:51
Joined
Mar 25, 2004
Messages
166
Hi Guys/Gals,

I got this code from somewhere on this forum awhile back but have run into a problem with it.

I have a combo that has "Current Month", "Current Quarter", etc. as well as one that says "Current Year". It should display 1/1/08 to 12/31/08. However it is showing 7/31/08 for the end date....

Can someone take a look at this and explain why the EndDate is always 1 month after the current month?


Case "Current Year"
Me.txtStartDate = DateSerial(Year(todaydate), Int((Month(todaydate) - 1) / 12) * 3 + 1, 1)
Me.txtEndDate = DateSerial(Year(todaydate), Int((Month(todaydate)) + 1) + 1, 0)
 
Simple Software Solutions

FDayOfYear = CDate("01/01/" & Year(Date()))

LDayOfYear = CDate("31/12/" & Year(Date()))

Use above to calculate the first and last days of the current year.
 
Check the formula for End Date

Hi Guys/Gals,

I got this code from somewhere on this forum awhile back but have run into a problem with it.

I have a combo that has "Current Month", "Current Quarter", etc. as well as one that says "Current Year". It should display 1/1/08 to 12/31/08. However it is showing 7/31/08 for the end date....

Can someone take a look at this and explain why the EndDate is always 1 month after the current month?


Case "Current Year"
Me.txtStartDate = DateSerial(Year(todaydate), Int((Month(todaydate) - 1) / 12) * 3 + 1, 1)
Me.txtEndDate = DateSerial(Year(todaydate), Int((Month(todaydate)) + 1) + 1, 0)

You are getting July instead of June because you are adding 1 during the Month Calculation (see Red above). Remove the 1 to get June

You can also get the Start date for this year with the following formula:

DateSerial(Year(now()), 1, 1),
 
Last edited:
Thanks guys for your replies.

The first part works great getting the first day of the 1/1 of the current year.

It is the last day of the year that is killing me.

I will try the suggestions listed. I have the same problem with the option "Last Year" it is the 12/31 XXXX that is getting me.
 
The first part works great getting the first day of the 1/1 of the current year.

IMNO purely by chance so far, have you tried it for July?

Me.txtStartDate = DateSerial(Year(todaydate), Int((Month(todaydate) - 1) / 12) * 3 + 1, 1)

Int((Month(todaydate) - 1) / 12) * 3 + 1

=int((7-1)/12)*3+1
=int(1.5)+1
=2
=Feb

Use Dcrake's formulae or

Dateserial(Year(date()),1,1)
Dateserial(Year(Date()),12,31)

No fancy calculations needed.

Brian
 
There is always an easier way isn't there...

Thanks yes it works. Always go simple first....
 

Users who are viewing this thread

Back
Top Bottom