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

Subract from date

Status
Not open for further replies.

mohebk

MIS
Aug 23, 2005
139
US
Hi,
I am trying to subract from date. The user wants to put a code like d,m, or y - number to subract that number from the day, month or year. I am using that linke below and it is giving some strange results.

The code for this line should look oke this (m-3) to subtract three months from today's date.

txtDateChanged.Text = DateSerial(Month(Date) - 3, Day(Date), Year(Date))

Thanks as always.

Mo
 
[tt]DateAdd()[/tt]

Code:
txtDateChanged.Text = DateAdd("m", -3, Date)

CMP

Funny thing about being unemployed, weekends don't mean quite so much, just means you get to hang out with your working friends. Primus
 
And read the help about DateSerial to discover the correct arguments.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
BTW,
How I can get one text box to read those codes and accept a date data type from the calendar. Right now I have a text field and a date field and I am copying the actual date field into the text field. The user clicks on a button to select from the calendar and on another button to calculate. Ideally, I would like to have one text field that would accept both data types and one button to open the calendar if the user does not have a D, M, or Y in the left most position. I tried to use the Mid function to split the logic based on the value in that first position but had a hill of a time and finally decided to have to buttons.

Mo
 
Huh?

Not sure what your doing with the [tt]Mid()[/tt] function. Maybe look at [tt]IsDate()[/tt] or [tt]CDate()[/tt] functions to validate user input and fire them [tt]AfterUpdate()[/tt] or [tt]OnChange()[/tt] for the input box?

CMP

Funny thing about being unemployed, weekends don't mean quite so much, just means you get to hang out with your working friends. Primus
 
I was using Mid to substring the left most digit if it is T, D, or Y I branch the logic to calculate. If the value is date I direct the logic to the calendar drop down. But that IsDate may work. I am trying it now.

Mo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top