6 Months Free & No Setup Fees ASP.NET Hosting!
Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » C# Language » Using Month Only in DateTime
       
Author Reply
John Smith
posted 5 posts
since Sep 06, 2010 
from

Using Month Only in DateTime

  Posted on: 09 Sep 2010       
I only want to change the MonthlyCalender Month to a variable(May) but for some reason i have to enter the full date which breaks my code, as i search for the month in the variable and then match it so it then excutes the code when it finds the string, below is the code;

             if (textDueDate.Contains("May"))
            {
                DateTime dt = new DateTime();
                clndDueDate.SetDate(dt.AddMonths(05));
                clndDueDate.Update();
                MessageBox.Show("Inside May");
            }
            else
            {

            }

This does nothing, So do i use SetDate property in a different way... since i added the month on the Monthly calender.

MessageBox is just my debugger :P

Maybe substring?

 DateTime dt = new DateTime(2001, 01, 01); //Works with full date

DateTime dt = new DateTime(null, 01, null); //Not working ;(

Thanks for reading
Bechir Bejaoui
posted  1449 posts
since  Dec 06, 2007 
from 

 Re: Using Month Only in DateTime
  Posted on: 09 Sep 2010        0  

Is your variable where your searching is type of string?
Every one among us was a beginner once.
http://dotnetuniver.blogspot.com/
John Smith
posted  5 posts
since  Sep 06, 2010 
from 

 Re: Using Month Only in DateTime
  Posted on: 09 Sep 2010        0  
Yes and i'll upload the rest of the source code
Bechir Bejaoui
posted  1449 posts
since  Dec 06, 2007 
from 

 Re: Using Month Only in DateTime
  Posted on: 11 Sep 2010        0  

Hi
I have a question why in May if section the code is different?
Every one among us was a beginner once.
http://dotnetuniver.blogspot.com/
John Smith
posted  5 posts
since  Sep 06, 2010 
from 

 Re: Using Month Only in DateTime
  Posted on: 11 Sep 2010        0  
Because i was trying so many different things, but doesn't seem to make a difference as they don't work.

Since MonthlyCalender doesn't accept month only for some reason from the DateTime, maybe i should try DateTimePicker.
krishna v
posted  16 posts
since  Feb 08, 2006 
from 

 Re: Using Month Only in DateTime
  Posted on: 11 Sep 2010        0  

I prefer not going with string in the month.  If culture varies, then your code wont work. U better go with Month Property.  As you said, u always want to use month, just ignore rest.  There is no constructor in DateTime which takes nullable values, which is not meaning ful way.
Otherwise create your own month enum .
 

 

Bechir Bejaoui
posted  1449 posts
since  Dec 06, 2007 
from 

 Re: Using Month Only in DateTime
  Posted on: 12 Sep 2010        0  

Hi
I m agree with you  krishna, so John could refactor his code by introducting an enumeration
enum Months{Jun,Feb,Mar,.........}; to avoid hard coding with strings
Every one among us was a beginner once.
http://dotnetuniver.blogspot.com/
       
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved