Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date comparsions

Status
Not open for further replies.

rac55

Programmer
Jul 1, 2003
62
AU
Hi

Does anyone know how to compare a date in a dataset to todays date?

My code is;
myDate=DateTime.Now()
Dim MyConnection As SqlConnection = New SqlConnection("server=(local); trusted_connection=true; database=ExamResults")
MyConnection.Open()

Dim MyDataCommand As SqlDataAdapter
Dim DS
DS = New DataSet()

'CHECK EXPIRY DATE
MyDataCommand = New SqlDataAdapter("SELECT * FROM tblExpiryDate WHERE (ExpYear = ' " & myYear & "')", MyConnection)
MyDataCommand.Fill(DS, "tblExpiryDate")
rsExpiry.DataSource = DS.Tables("tblExpiryDate").DefaultView
rsExpiry.DataBind()

if (rsExpiry.ListItems("tblExpiryDate").Item(2) < myDate)

Any help would really be appreciated
Thanks
 
Is the problem in the WHERE statement ExpYear... or the IF statement?

If it is on the WHERE, is the ExpYear a field or is it a Part of the date field? If it is a field what data type is it? Where is myYear set and what data type is it?


Hope everyone is having a great day!

Thanks - Jennifer
 
Assuming that myDate is of DateTime data type:
Code:
dim theDate as DateTime = Convert.ToDateTime(rsExpiry.ListItems("tblExpiryDate").Item(2))
if theDate < myDate then
  // do something
end if
 
Hi

Thanks for reply...the issue is with the if tag...I tried the code but it keeps returning:

'ListItems' is not a member of 'System.Web.UI.WebControls.DataList'. in the dim theDate as DateTime = Convert.ToDateTime(rsExpiry.ListItems("tblExpiryDate").Item(2))

Do you have any idea what is wrong?

Thanks

 
Oh...didn't pay attention, it's definetly wrong. Can you post the html for the rsExpiry DataList?
 
Are you trying to loop through the DataList items or only check the selected on?

Hope everyone is having a great day!

Thanks - Jennifer
 
Hi

Have just managed to get it working...using

Dim theDate as DateTime
theDate = Ds.Tables(0).Rows(0)("ExpDate")

if theDate < myDate then

Thank you so much for your help :0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top