0

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
http://i67.photobucket.com/albums/h292/Athono/THIS-1.png
How would it be done in C#?

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

Edited by pyTony: fixed formatting

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Mitja Bonca
0

It does work, you just didn't pay attention to the fact that it returns a value. DateTime is immutable, and any method to modify it returns a new DateTime, it does not alter the one you are using.

0

As Memorath said, DateTime cannot be changed. But you can parse it to string, and change the string to your own "datetime" format (but remember, this is not going to be a real DateTime value anylonger).

try this:

DateTime date = DateTime.Now.Date; 
string strDate = date.ToString("yyyy-MM-dd 00:00:00");

Edited by Mitja Bonca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.