views:

31

answers:

4

Hi i'm getting an error when using this code

Session("formatdate") = Left(drv.Row("booking_status"), 10)

Session("formatdate").ToString("dd-MMM-yyyy")

Can anyone suggest anything? I'm trying to convert my session to a friendly date format but it won't work

This is the error

Too many arguments to 'Public Overridable Function ToString() As String'.

Thanks

Jamie

+2  A: 

Left(drv.Row("booking_status"), 10) returns a String.

There is no overload for String.ToString() that takes a String as a parameter. You might want to try something like:

Session("formatdate") = DateTime.Parse(Left(drv.Row("booking_status"), 10)) _
                                .ToString("dd-MMM-yyyy");
Justin Niessner
A: 

I used a tool to convert from C# to VB, so here you go...

Dim formattedDate As String = [String].Format("{0:C}", Session("formatdate"))
TheGeekYouNeed
A: 

As Justin pointed out, there is no overload for String.ToString() that takes a string as a parameter. However, there are several overloads for DateTime.ToString(), one of which does take a string.
In order to take advantage of this method, you need to convert your Session("formatdate") to a DateTime object:

Session("formatdate") = Left(drv.Row("booking_status"), 10) = Left(drv.Row("booking_status"), 10)

DateTime temp;

// Ensure date parsed successfully
if (DateTime.TryParse(Session("formatdate"), out temp)
{
   string formattedDate = temp.ToString("dd-MMM-yyyy");
}

Note that if you know the format that Session("formatdate") will be in, you can use DateTime.TryParseExact() instead of just TryParse() to ensure that the date is parsed according to the proper format.

Donut
A: 

You need to store a DateTime in Session("formatdate") then use ((DateTime) Session("formatdate")).ToString("dd-MM-yyyy");

sh_kamalh