Results 1 to 2 of 2

Thread: Using DatePart vs. Year or Month etc.

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Location
    Winnipeg, MB Canada
    Posts
    1

    Question

    Does anyone know of a reason I should use the VB function DatePart() as opposed to using Year() or Month() if I want to extract the year or the month from a date. Is one maybe going to go away in a future release of VB? It just seems odd to have two fuctions that do the same thing.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    try this:

    Private Sub Form_Load()
    Dim TheDate As Date ' Declare variables.
    Dim Msg
    TheDate = Date
    Msg = "Year: " & DatePart("y", TheDate)
    MsgBox Msg

    Dim MyDate, MyYear
    MyDate = Date ' Assign a date.
    MyYear = Year(MyDate) ' MyYear contains 1969.
    MsgBox MyYear

    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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