Dates
-
Hi, I am trying to set the value of a DateTimePicker to the first of next month in a UK date format. ie every day this month (March) the DTP will read 01/04/2005 then next month it will read 01/05/2004. Anyone know how it can be done? I've sorted the month part out with AddMonth(1) but have no idea how to set the date to 01 each time? Please can someone help? Thanks in advance Scott
-
Hi, I am trying to set the value of a DateTimePicker to the first of next month in a UK date format. ie every day this month (March) the DTP will read 01/04/2005 then next month it will read 01/05/2004. Anyone know how it can be done? I've sorted the month part out with AddMonth(1) but have no idea how to set the date to 01 each time? Please can someone help? Thanks in advance Scott
Alright mate, not sure I understand your problem but hopefully the code below will help. DateTime startOfMonth = DateTime.Now.AddMonths(1); startOfMonth = startOfMonth.AddDays(-startOfMonth.Day + 1); The code add's one month to the current date and then defaults the date to the 1st of the month.
-
Alright mate, not sure I understand your problem but hopefully the code below will help. DateTime startOfMonth = DateTime.Now.AddMonths(1); startOfMonth = startOfMonth.AddDays(-startOfMonth.Day + 1); The code add's one month to the current date and then defaults the date to the 1st of the month.
Do keep in mind that the
DateTime
type always uses the Gregorian calendar, so you should use theCalendar
class to truly get the right date if not doing this strickly for theDateTimePicker
. See http://blogs.msdn.com/michkap/archive/2005/03/28/402839.aspx[^] for more information. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog] -
Hi, I am trying to set the value of a DateTimePicker to the first of next month in a UK date format. ie every day this month (March) the DTP will read 01/04/2005 then next month it will read 01/05/2004. Anyone know how it can be done? I've sorted the month part out with AddMonth(1) but have no idea how to set the date to 01 each time? Please can someone help? Thanks in advance Scott