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!

Date Manipulation

Status
Not open for further replies.

capone67

Programmer
Nov 6, 2000
115
CA
Hi Gang

I am working on a project that is tightly tied to dates. I need to be able to subtract a day from a date. Is there a function in VB that will do this? I can't seem to find one. Alternatively, does anyone know where I could find the code for such a function? No sense in re-inventing the wheel here.

TIA

Ken
 
Lookup DateAdd in the online help, it will allow you to do this. DateDiff is another one to look at Snaggs
tribesaddict@swbell.net
 
how about use instr() to get the day if you know the format of date?
 
Use dateadd() in visual basic (see msdn help) to add or subtract values to one specific date. In other words, to add a day to '1/1/2000' or subtract a month from '3/31/2000'
(When using dateadd, you are adding a negative to subtract the date!)

Use datediff() if you want to determine the difference between 2 dates and what format is the difference (e.g., in days, months, hours, etc.) How many days difference between '1/1/2000' and '1/3/2000' is 2.

bye
Jim
 
Thanks Guys

DateAdd was the ticket.

Jimgao, things start getting complex though if you need to see the previous day on the first day of the month and even more enjoyable if it is the first day of the year.

Ken
 
It does not matter what day of the year it is,

DateAdd("d", -1, Now())

will give you the previous day.

Simon
 
Sorry for the miss understanding. What I was trying to convey was that if I used the instr() command to manipulate the date myself I would need to deal with month and year changes. Seems to me this would be an awful lot of overhead in comparison to using a VB function.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top