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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use build-in function to automatically select dates. 1

Status
Not open for further replies.

Goondu

Technical User
Jan 14, 2004
92
SG
I have users inputing into two textboxes “StartDate” and “EndDate”. I need the function to return base on the textbox input. For example,

“01-Jul-08” in the “StartDate” textbox
“31-Jul-08” in the “EndDate” textbox

The return results when the user clicks the button

“01-Jun-08” for “StartDate”
“30-Jun-08” for “EndDate”

or if the user input “01-Mar-08” and “31-Mar-08” respectively

“01-Feb-08”
“29-Feb-08”

I need to use the results for calculating the used quantity from a table in the previous month.

Thanks
 
You can use DateAdd:

DateAdd("m", -1, StartDate)
 
?dateadd("m",-1,#2008-02-29#)
29/01/2008
I think
Code:
NewStartDate = DateSerial(Year(StartDate), Month(StartDate)-1, 1)
NewEndDate = DateSerial(Year(EndDate), Month(EndDate), 0)
 
Thanks Remou and Jerry for the reply.

Not so good. The DateAdd() did not include the complete days needed.

For example,

Code:
StartDate = #01-Apr-08#
EndDate = #30-Apr-08#

The Result output must be,
#01-Mar-08#
#31-Mar-08#

DateAdd() the out of #01-Mar-08# and #30-Mar-08#.Missing a day.

 
No dice, Jerry.

Same as DateAdd, still picking up 30 instead of 31.
 
Wait...

I mistook the 0 for -1.

That did it, Thanks Jerry.
Will see if it works live database.
 

It should, because I tested with this 2008-02-29 date

Thanx for the pinky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top