How to retrieve only years from date time picker

chanlichin

New member
Joined
Aug 24, 2009
Messages
2
Programming Experience
Beginner
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


VB.NET:
      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
 
Hi,

You may use the YEAR or DATENAME function.
for eg,
VB.NET:
sql = "SELECT YEAR(dates) AS [Year] FROM summary WHERE plants = '" & yieldsummary.cbPlant.Text & "'"

VB.NET:
sql = "SELECT DATENAME(yy,dates) AS [Year] FROM summary WHERE plants = '" & yieldsummary.cbPlant.Text & "'"

Regards,
Ajeesh
 
Year can not display

Come out the error "Column 'dates' does not belong to the table summary....May i ask i need to decare anything for the date function?Thanks
 
VB.NET:
select * from yourTable where datepart(yyyy, dateCol) = 2007
 
Back
Top