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

Getting date of 100 days ago 1

Status
Not open for further replies.

AT76

Technical User
Apr 14, 2005
460
US
Hi,

I have a date in format YYYYMMDD which I need to get the date from 100 days ago. Here's what I'm trying to do:

Dim date100DaysAgo As String = Format(Now() - 100, "yyyyMMdd")

However, I get a syntax error: in Now() - 100 which says: "Operator '-' is not defined for types 'Date' and 'Integer'. Any thoughts as to how I can overcome this?

Thank you!
 
Dim date100DaysAgo As String = Format(Date.Today.AddDays(-100), "yyyyMMdd")

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
This also will work.
Code:
MessageBox.Show(Format(DateAdd(DateInterval.Day, -100, Now()), "yyyyMMdd"))


________________________________________________________
Zameer Abdulla
Help to find Missing people
Even a thief takes ten years to learn his trade.
 
Format(Now() - 100, "yyyyMMdd") works in VBA and VB 6 because dates and times are numbers (doubles - I think) with date the integer part and time the fractional part.

In .NET date and time is a structure so you can't carry out arithmetical actions directly, which is why you need to use either the solution offered by jebenson or ZmrAbdulla.

Hope this helps.

[vampire][bat]
 
Thank you all. Earthandfire: thank you for explaining the difference. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top