Results 1 to 7 of 7

Thread: Simple date question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    95

    Simple date question

    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,

  2. #2
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    Ray, try this.

    VB Code:
    1. Dim curdate As New Date()
    2.         Dim nextmonth As Date
    3.         curdate = System.DateTime.Today
    4.  
    5.         nextmonth = curdate.AddMonths(1)
    6.         nextmonth = New Date(nextmonth.Year, nextmonth.Month, 1)
    7.  
    8.         MessageBox.Show("First day of next month: " & nextmonth.ToString())
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    95
    Very smooth. Thanks

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Mr.No Good Job !
    I was doing something quite similar but this error was preventing me running the code .

    VB Code:
    1. 'this code is fine
    2. Dim Td As Date
    3. Dim NxM As Date
    4. MsgBox("Today is  " & DateTime.Today)
    5.  
    6. 'but when I assign the vari Td like so , I get error says :
    7. ' Value of type 'Date' cannot be converted to '1-dimensional array
    8. 'of Date'.
    9. Dim Td As Date()
    10. Dim NxM As Date
    11. MsgBox("Today is  " & DateTime.Today)
    12.  
    13. 'the error shows in the next two lines
    14. Td = DateTime.Today         ' 1
    15. NxM = Td.AddMonths(1)      '2
    16. MsgBox(NxM.ToString)
    Cany anyone explain this . thanx .

  5. #5
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    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:
    1. Dim Td As New Date()  ' New is required
    2.         Dim NxM As Date
    3.         Dim NxM2 As Date
    4.         Dim td2 As New DateTime() ' New is required
    5.         MsgBox("Today is  " & DateTime.Today)
    6.  
    7.         'the error shows in the next two lines
    8.         'system.DateTime. The error is not occur anymore when
    9.        '  you use the New keyword while declaring Td.
    10.         Td = DateTime.Today()        ' 1
    11.         td2 = DateTime.Today()
    12.         NxM = Td.AddMonths(1)      '2
    13.         NxM2 = td2.AddMonths(1)
    14.         MessageBox.Show(NxM.ToString)
    15.         MessageBox.Show(NxM2.ToString)
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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:
    1. Dim Td As Date   ' New is required
    2. Dim NxM As Date
    3.  Dim NxM2 As Date
    4.  Dim td2 As DateTime ' New is required
    5.  MsgBox("Today is  " & DateTime.Today)
    6.  
    7.  'the error shows in the next two lines
    8.  'system.DateTime. The error is not occur anymore when
    9.  '  you use the New keyword while declaring Td.
    10.  Td = DateTime.Today()        ' 1
    11.  td2 = DateTime.Today()
    12. NxM = Td.AddMonths(1)      '2
    13.  NxM2 = td2.AddMonths(1)
    14. MessageBox.Show(NxM.ToString)
    15.  MessageBox.Show(NxM2.ToString)

  7. #7
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    Sorry pirate

    I can't think of anything yet.
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width