Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Formatting

Status
Not open for further replies.

Hayton

Technical User
Joined
Oct 17, 2001
Messages
257
Location
NZ
I have a form with a textbox called txtBeginDate. I enter a date into this textbox and it will always be the first of the month. ie 01/04/07.

I wish to display the date for the previous 12 months in another textbox called txtPrevious. I have used this to do that =DateSerial(Year([txtBegindate]),Month([txtBegindate])-13,Day([txtBegindate])). This shows the date as 01/03/06

However I would like the last day of the month to appear and not the 1st day of the month in txtPrevious ie the 30th or 31st. In the case above it would be 31/03/06.

Any suggestions will be appreciated.

Hayton McGregor

 
minus the 12 months, then minus 1 day

Code:
=DateSerial(Year([txtBegindate]),Month([txtBegindate])-12,Day([txtBegindate])-1)

Should be what you are looking for.

Hope this helps.

Michael
 
Thanks micanguk. Your suggestion works just fine.

Hayton McGregor

 
Excellent, my pleasure.

Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top