Connecting Tech Pros Worldwide Forums | Help | Site Map

Date functions in c#

Kiran
Guest
 
Posts: n/a
#1: Nov 16 '05
Hi,

Please help on date functions in C#.

I would like to know the relevant exampl to retrieve
2 weeks before date from the current date,
1 month before date from the current date and number of days.
2 months before date from the current date and number of days.
3 months before date from the current date and number of days.
8 months before date from the current date and number of days.
1 year before date from the current date and number of days.

Pls help...

Regards,
Krian

Chavdar Kulin
Guest
 
Posts: n/a
#2: Nov 16 '05

re: Date functions in c#


Hi! You can use someting like

DateTime dt = DateTime.Today.AddMonths(-2).AddDays(-3);

//Today 2 months before and 3 days

or

DateTime dt = DateTime.Today.AddYears(-1).AddMonths(-2).AddDays(-3);

//One year , two months and 3 days before.



"Kiran" <kiran_rallabandi@yahoo.com> wrote in message
news:9d281153.0409122200.5b701a51@posting.google.c om...[color=blue]
> Hi,
>
> Please help on date functions in C#.
>
> I would like to know the relevant exampl to retrieve
> 2 weeks before date from the current date,
> 1 month before date from the current date and number of days.
> 2 months before date from the current date and number of days.
> 3 months before date from the current date and number of days.
> 8 months before date from the current date and number of days.
> 1 year before date from the current date and number of days.
>
> Pls help...
>
> Regards,
> Krian[/color]


Bruno Jouhier [MVP]
Guest
 
Posts: n/a
#3: Nov 16 '05

re: Date functions in c#


You should take a look at the System.DateTime and System.TimeSpan
documentation.

Bruno.

"Kiran" <kiran_rallabandi@yahoo.com> a écrit dans le message de news:
9d281153.0409122200.5b701a51@posting.google.com...[color=blue]
> Hi,
>
> Please help on date functions in C#.
>
> I would like to know the relevant exampl to retrieve
> 2 weeks before date from the current date,
> 1 month before date from the current date and number of days.
> 2 months before date from the current date and number of days.
> 3 months before date from the current date and number of days.
> 8 months before date from the current date and number of days.
> 1 year before date from the current date and number of days.
>
> Pls help...
>
> Regards,
> Krian[/color]


Mark Rae
Guest
 
Posts: n/a
#4: Nov 16 '05

re: Date functions in c#


"Kiran" <kiran_rallabandi@yahoo.com> wrote in message
news:9d281153.0409122200.5b701a51@posting.google.c om...
[color=blue]
> Please help on date functions in C#.[/color]

Have a look at the DateTime object, then its AddDays, AddWeeks, AddMonths
and AddYears methods. To go back in time, you just "add" a negative amount
of units.



Peter Rilling
Guest
 
Posts: n/a
#5: Nov 16 '05

re: Date functions in c#


Have you looked at all the Add* methods in the DateTime structure. Just
pass a negative value if you want dates before the specified date.

"Kiran" <kiran_rallabandi@yahoo.com> wrote in message
news:9d281153.0409122200.5b701a51@posting.google.c om...[color=blue]
> Hi,
>
> Please help on date functions in C#.
>
> I would like to know the relevant exampl to retrieve
> 2 weeks before date from the current date,
> 1 month before date from the current date and number of days.
> 2 months before date from the current date and number of days.
> 3 months before date from the current date and number of days.
> 8 months before date from the current date and number of days.
> 1 year before date from the current date and number of days.
>
> Pls help...
>
> Regards,
> Krian[/color]


David Browne
Guest
 
Posts: n/a
#6: Nov 16 '05

re: Date functions in c#



"Kiran" <kiran_rallabandi@yahoo.com> wrote in message
news:9d281153.0409122200.5b701a51@posting.google.c om...[color=blue]
> Hi,
>
> Please help on date functions in C#.
>
> I would like to know the relevant exampl to retrieve
> 2 weeks before date from the current date,
> 1 month before date from the current date and number of days.
> 2 months before date from the current date and number of days.
> 3 months before date from the current date and number of days.
> 8 months before date from the current date and number of days.
> 1 year before date from the current date and number of days.
>[/color]

DateTime.AddXXX

EG current date minus one month and 6 days.

DateTime.Now.Date.AddMonths(-1).AddDays(-6)

David




Closed Thread