Click here to Skip to main content
15,999,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..
i've two datefield i want to
print the date in that
in one datefield date 1/present month/2011
and in second datefield presentDate/presentMonth/2011..

how to do this...
help me..
Posted

Hi,

Try the following Code....

DateTime dt1 = DateTime.Now.Date;
DateTime dt2 = dt1.Date.AddDays(-1* (dt1.Day - 1));


Now you get Current Date in dt1 and also get first date of that month in dt2

Set those values in your date control.

Cheers :)
 
Share this answer
 
Comments
Manfred Rudolf Bihy 24-Jan-11 8:23am    
Sneaky date arithmetic! 5+ :)
You can get it done like this:

C#
// format string to format the date like you need it
String formatString = "dd/MM/yyyy";
DateTime now = DateTime.Now;
DateTime date = new DateTime(now.Year, now.Month, 1); // create a date with current year and month and day 1
textBox1.Text = date.ToString(formatString);
textBox2.Text = now.ToString(formatString);


That should do it for you!

Please also refer to this page to learn all about DateTime format strings:http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx[^]

Best Regards,
Manfred
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900