Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to create a date exactly 90 earlier. Add days with a negative value gives me this error:

Conversion from string "02/09/2011" to type 'Long' is not valid.

VB
New Date(Now.AddDays(-90).ToShortDateString)
Posted
Updated 1-Dec-11 3:15am
v2
Comments
Amir Mahfoozi 1-Dec-11 8:23am    
What is your programming language ?

If you are assigning String Value as a Date then this Error occurs.
There is no constructor for Date which take Date in String format as it is.Try this one :
VB
Dim _Date As Date = New Date("2011", 12, "1")
MessageBox.Show(_Date.Month - 3)

I hope it will help you. :)
 
Share this answer
 
DateTime.Today.DayOfYear - 90
 
Share this answer
 
What's wrong with:
VB
Dim dt As Date = Now.AddDays(-90)

?
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Dec-11 14:11pm    
Exactly. I mean, nothing wrong :-), a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900