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
[IMG]http://i67.photobucket.com/albums/h292/Athono/THIS-1.png[/IMG]
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]


Mayur GujrathiRank #666 · 3.6K reputationPosted Sep 22, 2011, 12:09 AM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 22, 2011, 12:11 AM EDT
DateTime dt = DateTime.Now.AddMonths(-1);
Console.WriteLine("{0:yyyy-MM-dd 00:00:00:000}", dt);
producing the expected output of :
2011-08-22 00:00:00:000
Dorababu MekaRank #457 · 5.5K reputationPosted Sep 22, 2011, 12:18 AM EDT