get date
am 02.04.2008 14:24:08 von MikeIf I have a date such as 4/2/2008, is there a way to go back a month such as
3/2/2008?
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 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
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?
>
>
>
>
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"
news:mn.13797d847e488316.82533@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
>
>
I got it, its dt.AddMonths(-1);
"Hans Kesting"
news:mn.13797d847e488316.82533@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
>
>
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]"
news:85EEB8F8-80A7-410E-99A9-4CCB4A3754FC@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 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)