get date

If I have a date such as 4/2/2008, is there a way to go back a month such as
3/2/2008?
Mike [ Mi, 02 April 2008 14:24 ] [ ID #1933641 ]

Re: get date

Mike explained :
> If I have a date such as 4/2/2008, is there a way to go back a month such as
> 3/2/2008?

DateTime dt = new DateTime(2008,4,2);
dt = dt.AddMonth(-1);


Hans Kesting
Hans Kesting [ Mi, 02 April 2008 14:49 ] [ ID #1933646 ]

RE: get date

DateTime myDate = DateTime.Parse("4/2/2008");
DateTime olderDate = myDate.AddMonths(-1);
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net


"Mike" wrote:

> If I have a date such as 4/2/2008, is there a way to go back a month such as
> 3/2/2008?
>
>
>
>
pbromberg [ Mi, 02 April 2008 14:50 ] [ ID #1933647 ]

Re: get date

I've tried it and it gives me this error when I try to compile it:


DateTime dt = new DateTime(2008,4,2);
dt = dt.AddMonth(-1);

Error 24 'System.DateTime' does not contain a definition for 'AddMonth'

"Hans Kesting" <invalid.hansdk [at] spamgourmet.com> wrote in message
news:mn.13797d847e488316.82533 [at] spamgourmet.com...
> Mike explained :
>> If I have a date such as 4/2/2008, is there a way to go back a month such
>> as 3/2/2008?
>
> DateTime dt = new DateTime(2008,4,2);
> dt = dt.AddMonth(-1);
>
>
> Hans Kesting
>
>
Mike [ Mi, 02 April 2008 14:55 ] [ ID #1933648 ]

Re: get date

I got it, its dt.AddMonths(-1);


"Hans Kesting" <invalid.hansdk [at] spamgourmet.com> wrote in message
news:mn.13797d847e488316.82533 [at] spamgourmet.com...
> Mike explained :
>> If I have a date such as 4/2/2008, is there a way to go back a month such
>> as 3/2/2008?
>
> DateTime dt = new DateTime(2008,4,2);
> dt = dt.AddMonth(-1);
>
>
> Hans Kesting
>
>
Mike [ Mi, 02 April 2008 14:56 ] [ ID #1933650 ]

Re: get date

here is what I need.
I need to get todays date, then subtract the month and then pass only the
month to my database.
I have this;

DateTime dtToday = System.DateTime.Now;
//which gives me 4/2/2008

I then need to create a date of 3/2/2008 and only pass that month.
So if its 4/20/2008 I need to get 3/20/2008 and pass the 3.

If I do this
DateTime dt = DateTime.Parse(dtToday);
dt = dt.AddMonths(-1);

I'm getting the following error:
Error 24 The best overloaded method match for
'System.DateTime.Parse(string)' has some invalid arguments

and

Error 25 Argument '1': cannot convert from 'System.DateTime' to 'string'



"Peter Bromberg [C# MVP]" <pbromberg [at] yahoo.NoSpamMaam.com> wrote in message
news:85EEB8F8-80A7-410E-99A9-4CCB4A3754FC [at] microsoft.com...
> DateTime myDate = DateTime.Parse("4/2/2008");
> DateTime olderDate = myDate.AddMonths(-1);
> -- Peter
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short Urls & more: http://ittyurl.net
>
>
> "Mike" wrote:
>
>> If I have a date such as 4/2/2008, is there a way to go back a month such
>> as
>> 3/2/2008?
>>
>>
>>
>>
Mike [ Mi, 02 April 2008 15:10 ] [ ID #1933651 ]

Re: get date

Mike brought next idea :
> here is what I need.
> I need to get todays date, then subtract the month and then pass only the
> month to my database.
> I have this;
>
> DateTime dtToday = System.DateTime.Now;
> //which gives me 4/2/2008
>
> I then need to create a date of 3/2/2008 and only pass that month.
> So if its 4/20/2008 I need to get 3/20/2008 and pass the 3.
>
> If I do this
> DateTime dt = DateTime.Parse(dtToday);
> dt = dt.AddMonths(-1);
>
> I'm getting the following error:
> Error 24 The best overloaded method match for 'System.DateTime.Parse(string)'
> has some invalid arguments
>
> and
>
> Error 25 Argument '1': cannot convert from 'System.DateTime' to 'string'
>

You supplied a "DateTime" agrument to Parse, where it expected a
string.
Just use
DateTime dtToday = System.DateTime.Now;
DateTime dtLastMonth = dtToday.AddMonths(-1);

Hans Kesting
(sorry for the typo in my previous post)
Hans Kesting [ Mi, 02 April 2008 15:26 ] [ ID #1933654 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » get date

Vorheriges Thema: logging to a text file in high demand environment
Nächstes Thema: TreeView Control