How to retrives only years from date time picker

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chanlichin
    New Member
    • Aug 2009
    • 4

    How to retrives only years from date time picker

    Hi, I am now want to retrieve only year from my table(summary), field name(dates). So i am facing the problem on how to display the year in combo Box. my sql statement as below. Thanks

    If i put SELECT DATES, that means day,month and year will display. So, what should i put after SELECT.
    Code:
    con.Open()
    
                sql = "SELECT dates FROM summary WHERE plants = '" & yieldsummary.cbPlant.Text & "'"
                da = New OleDb.OleDbDataAdapter(sql, con)
                da.Fill(ds, "summary")
    
                con.Close()
                maxrow = ds.Tables("summary").Rows.Count
    
                For x = 0 To maxrow - 1
    
                    cbYear.Items.Add(ds.Tables("summary").Rows(x).Item("dates"))
                    cbYear1.Items.Add(ds.Tables("summary").Rows(x).Item("dates"))
    
                Next x
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What does this question have to do with a date time picker?

    Anyways, are you retrieving Dates from the Database? Or Strings?

    Comment

    • chanlichin
      New Member
      • Aug 2009
      • 4

      #3
      Display in Combo box

      I am using Ms Access. My field name(dates),dat a type(date/time) in the format mm/d/yyyy
      So i just want retrieve only year from database without duplicate the year. So i have the problem in writting sql statement
      .

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Since(I think) you have a DateTime Structure you can use the DateTime's Year Property to retrieve the year.......

        Comment

        Working...