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

Adding or Subtracting a Date by 1 Day 2

Status
Not open for further replies.

Modex

Programmer
Sep 15, 2002
155
0
0
GB
Hi All,

I have a little problem with date manipulation.
Basically I have a button on a form that is called [TODAY], if the user clicks on this button then only the records for today are shown on the form (using the filter option in code). However, what I would like to do is have a couple of extra buttons on the form to allow the user to select [yesterday] or [tomorrow], therfore basically adding 1 day or subtracting one day to todays date and then performing the filter operation.

The problem I have is how do you increment(or decrement) a date. I have searched through the TEK-TIPS Archive but could find nothing that would help.

If anyone could throw any light on this, I would be really grateful.


Cheers

ModeX :)
 
Simple, just add or subtract 1 from the Date()
Date() = 1/10/05
Date()-1 = 1/9/05
Date()+1 = 1/11/05

Dates are stored as integers from December 31, 1899 (thanks Golom) so December 31 1899 was 1, today is 31362, tomorrow is 3163 and yesterday was 31361.

Paul
 
Function DateAdd(Interval As String, Number As Double, Date)

Yesterday = DateAdd("d", -1, Date())
Tomorrow = DateAdd("d", 1, Date())

mike
 
Sorry, should have put my glasses on before. Today's value as an integer is NOT 31362, its 38362 and yesterday is one less and tomorrow is one more. Also, Time is stored as a Decimal so when viewing Now() as a Double datatype, Now() = 38362.6595833333
plus or minus the few seconds it took to copy it to this post.

Paul
 
Hi Mike and Paul

Many thanks for that, I appreciate the responses, you were right is fairly simple, I was trying to just +1 to the date.

I feel embarassed, I'll just put it down to the fact Ive just turned 50 and the old brain cells aren't what they used to be.

Again, thanks alot guys, much apprecited

ModeX
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top