I should know this, but how do you find the first day of the next month. Today is 1/22/2003. I need 2/01/2003.
Thanks much,
Printable View
I should know this, but how do you find the first day of the next month. Today is 1/22/2003. I need 2/01/2003.
Thanks much,
Ray, try this.
VB Code:
Dim curdate As New Date() Dim nextmonth As Date curdate = System.DateTime.Today nextmonth = curdate.AddMonths(1) nextmonth = New Date(nextmonth.Year, nextmonth.Month, 1) MessageBox.Show("First day of next month: " & nextmonth.ToString())
Very smooth. Thanks
Mr.No Good Job !
I was doing something quite similar but this error was preventing me running the code .
Cany anyone explain this . thanx .VB Code:
'this code is fine Dim Td As Date Dim NxM As Date MsgBox("Today is " & DateTime.Today) 'but when I assign the vari Td like so , I get error says : ' Value of type 'Date' cannot be converted to '1-dimensional array 'of Date'. Dim Td As Date() Dim NxM As Date MsgBox("Today is " & DateTime.Today) 'the error shows in the next two lines Td = DateTime.Today ' 1 NxM = Td.AddMonths(1) '2 MsgBox(NxM.ToString)
pirate
I tried the following to avoid the errors. It seems that you have to create an instance of td using New to allow it receive the Today property from the DateTime structure. Strangely enough the DateTime text doesn't become blue in the IDE.
I added the variables appended with 2 to try variables of type DateTime.
VB Code:
Dim Td As New Date() ' New is required Dim NxM As Date Dim NxM2 As Date Dim td2 As New DateTime() ' New is required MsgBox("Today is " & DateTime.Today) 'the error shows in the next two lines 'system.DateTime. The error is not occur anymore when ' you use the New keyword while declaring Td. Td = DateTime.Today() ' 1 td2 = DateTime.Today() NxM = Td.AddMonths(1) '2 NxM2 = td2.AddMonths(1) MessageBox.Show(NxM.ToString) MessageBox.Show(NxM2.ToString)
mr.no , here is your code back with little change . It works fine as I'm saying, no need to instantiate a new object of Date and DateTime Classes.They seem to be Static Classes(Shared).The problem back when I add two parenthesis at the end.It has something to do with damn arrays.
VB Code:
Dim Td As Date ' New is required Dim NxM As Date Dim NxM2 As Date Dim td2 As DateTime ' New is required MsgBox("Today is " & DateTime.Today) 'the error shows in the next two lines 'system.DateTime. The error is not occur anymore when ' you use the New keyword while declaring Td. Td = DateTime.Today() ' 1 td2 = DateTime.Today() NxM = Td.AddMonths(1) '2 NxM2 = td2.AddMonths(1) MessageBox.Show(NxM.ToString) MessageBox.Show(NxM2.ToString)
Sorry pirate
I can't think of anything yet.