Connecting Tech Pros Worldwide Forums | Help | Site Map

How to retrives only years from date time picker

Newbie
 
Join Date: Aug 2009
Posts: 4
#1: Aug 24 '09
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.
Expand|Select|Wrap|Line Numbers
  1. con.Open()
  2.  
  3.             sql = "SELECT dates FROM summary WHERE plants = '" & yieldsummary.cbPlant.Text & "'"
  4.             da = New OleDb.OleDbDataAdapter(sql, con)
  5.             da.Fill(ds, "summary")
  6.  
  7.             con.Close()
  8.             maxrow = ds.Tables("summary").Rows.Count
  9.  
  10.             For x = 0 To maxrow - 1
  11.  
  12.                 cbYear.Items.Add(ds.Tables("summary").Rows(x).Item("dates"))
  13.                 cbYear1.Items.Add(ds.Tables("summary").Rows(x).Item("dates"))
  14.  
  15.             Next x
  16.  

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#2: Aug 24 '09

re: How to retrives only years from date time picker


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

Anyways, are you retrieving Dates from the Database? Or Strings?
Newbie
 
Join Date: Aug 2009
Posts: 4
#3: Aug 25 '09

re: How to retrives only years from date time picker


I am using Ms Access. My field name(dates),data 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
.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#4: Aug 25 '09

re: How to retrives only years from date time picker


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