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

Recommended Answers

All 2 Replies

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.

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");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.