[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

format string to remove day of week

I am using VS.NET 2003 and need to display date but dont want the day of the week...so my string is currently....
Wednesday, April. 23, 2008
I created a case statement to check and truncate the month from April to Apr.
now i want to remove the day of the week, can I do this easier than doing a case statement and a replace, for each day of the week, looking for something with less code, perhaps an array type of idea...but not sure on how to go about that.

Wednesday, Apr. 23, 2008
  • 2
1 Solution
käµfm³d 👽Commented:
So something like below doesn't work for you?
DateTime d = new DateTime(2009, 5, 1);
d.ToString("MMM dd, yyyy")

Open in new window

solraccheffyAuthor Commented:
getting this error...
Argument '1': cannot convert from 'string' to 'long'
The best overloaded method match for 'System.DateTime.DateTime(long)' has some invalid arguments

The string I am passing is "Wednesday, April 23, 2008" does not work in your example.

DateTime newDate = new DateTime(FormattedDate);
return newDate.ToString("MMM dd, yyyy");
käµfm³d 👽Commented:
What about:
Convert.ToDateTime("Wednesday, April 23, 2008").ToString("MMM dd, yyyy");

Open in new window

Snippet to ponder

String date = "Wednesday, Apr. 23, 2008";
  String parts = date.Split (",");
  date = parts[1]+","+parts[2];

Open in new window


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now