We help IT Professionals succeed at work.

Argument 'DateValue' cannot be converted to type 'Date'.

gianitoo
gianitoo asked
on
Medium Priority
1,410 Views
Last Modified: 2012-05-06
Argument 'DateValue' cannot be converted to type 'Date'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Argument 'DateValue' cannot be converted to type 'Date'.

Source Error:


Line 8:        dim deletedate as string=""
Line 9:  
Line 10:       if appsettings.showlastdays>0 then deletedate=getdate(dateadd("d",-appsettings.showlastdays,todaydatetime))

 

dim deletedate as string=""
 
	if appsettings.showlastdays>0 then deletedate=getdate(dateadd("d",-appsettings.showlastdays,todaydatetime))

Open in new window

Comment
Watch Question

Is todaysdatetime a datetime variable? Try this instead
Convert.ToDateTime(todaydatetime).AddDays(-appsettings.showlastdays).ToShortDateString()

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
so it will be??
if appsettings.showlastdays>0 then deletedate=Convert.ToDateTime(todaydatetime).AddDays(-appsettings.showlastdays).ToShortDateString()
Yes

Author

Commented:
i get this error
Exception Details: System.FormatException: String was not recognized as a valid DateTime.

dim deletedate as string=""

if appsettings.showlastdays>0 then deletedate=Convert.ToDateTime(todaydatetime).AddDays(-appsettings.showlastdays).ToShortDateString()
Can you tell me what is the value for todaysdatetime?

Author

Commented:
has to be a datetime value.......
Yes I know if has to be a datetime value but can you tell me what is the value of it when you execute the code so that I can see what is wrong?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.