How do I get a dattime format in C# that will

September 22, 2011 at 00:00:21
Specs: Windows 7
How do I get a dattime format in C# that will look like this:

2011-09-01 00:00:00:000
This works
DateTime saveNow = DateTime.Now;

string test = String.Format("{0:yyyy-MM-01 00:00:00:000}", saveNow);

Now I want to know this. How would I subtract one month from the current month?

It T-SQL it would look like this

How would it be done in C#?


trying the addmonth method with a negative one did not work
[IMG]http://i67.photobucket.com/albums/h292/Athono/thisdidnotwork.png[/IMG]


See More: How do I get a dattime format in C# that will

Report •


#1
September 22, 2011 at 05:57:05
To quote MSDN:
This method does not change the value of this DateTime object. Instead, it returns a new DateTime object whose value is the result of this operation

EDIT:
Practical example:

static void Main(string[] args) {
  var foo = System.DateTime.Now;
  var bar = foo.AddMonths(-1);
  System.Console.WriteLine("Foo: {0:MMM}\nBar: {1:MMM}", foo, bar);
}

Produces:
Foo: Sep
Bar: Aug

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question