dates - subtract 12 months

  • Thread starter Thread starter Jimbo
  • Start date Start date
DateTime twelveMonthsPrevious = DateTime.Now.AddMonths(-12);
twelveMonthsPrevious = DateTime.Now.AddYears(-1);
 
Hi Jimbo,

You can use AddMonths method and pass -12 as the parameter. Which basically subtracts 12 months from the date. Basically the method does both add and subtract.

check this link,

<http://msdn.microsoft.com/library/d...ml/frlrfsystemdatetimeclassaddmonthstopic.asp>

Hope this helps...

Regards,
Madhu

MVP | MCSD.NET

----- Jimbo wrote: -----

Anyone know how I can subtract 12 months from the current date?

Hi, thanks for that. But how can I covert the date to different regional
areas - usa mm/dd/yyyy, euro dd/mm/yyyy ?
 
Jimbo,

You can get different string representations of the date by passing
parameters to the ToString method on the DateTime instance. Check out the
documentation for the DateTimeFormatInfo class to find the string formats
you can pass to the ToString method to output different formats for the
DateTime instance.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

basically subtracts 12 months from the date. Basically the method does both
add and subtract.
 
Jimbo,

You can get different string representations of the date by passing
parameters to the ToString method on the DateTime instance. Check out the
documentation for the DateTimeFormatInfo class to find the string formats
you can pass to the ToString method to output different formats for the
DateTime instance.

Hope this helps.

Easy peasy, thanks a bunch.
 
Jimbo said:
Hi, thanks for that. But how can I covert the date to different regional
areas - usa mm/dd/yyyy, euro dd/mm/yyyy ?

Use the appropriate CultureInfo to regionalise date output; for example:

DateTime dt = DateTime.Now;

CultureInfo usCulture = CultureInfo.CreateSpecificCulture("en-US");
CultureInfo ukCulture = CultureInfo.CreateSpecificCulture("en-GB");

Console.WriteLine(dt.ToString(usCulture));
Console.WriteLine(dt.ToString(ukCulture));

Console.WriteLine(dt.ToString("D", usCulture));
Console.WriteLine(dt.ToString("D", ukCulture));

Hope this helps
 
Back
Top