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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare dates from Access and Now()

Status
Not open for further replies.

manguilla

Programmer
Jul 20, 2004
52
US
Hello Everyone.

I have a quick question about comparing dates. For some reason I cannot figure this out and I know it should be real easy. Here is the situation that I need help on. I have a database in access and I need to compare the 'date' column with today's date and see if it's someones birthday. The 'date' column format in access is 12/15/2004. So what I need to do in VB.NET is compare the 12/15/2004 to someone that could have a birthday on 12/15/1975 in the 'date' column. I know I need to compare the 12/15 but how do I do that? Any help will do. Here is the code I have so far. Thank you in advance.


Manguilla


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim connString As String
Dim dbConn As System.Data.IDbConnection
Dim queryDate As String
Dim currDate As String
Dim resultEMAIL As String
Dim resultBDAY As String

connString = "Provider = Microsoft.Jet.Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\temptest\Birthdays.mdb"
dbConn = New System.Data.OleDb.OleDbConnection(connString)

queryDate = "SELECT date from birthday"
currDate = Now()
'resultBDAY =
resultEMAIL = "SELECT email from birthday where date = "

objOutlook = CreateObject("Outlook.Application")
objOutlookMsg = objOutlook.CreateItem(Outlook.OlItemType.olMailItem)

With objOutlookMsg
'.To = resultBDAY
.To = "chadenes@hotmail.com"
.Subject = "Happy Birthday"
.HTMLBody = "<html><head></head><body><p>Test Email</p></body></html>"
.Send()

End With

objOutlook = Nothing

MsgBox("Email was sent successfully")
End Sub

End Class
 
I think I would take the twisted approach of stripping off the year and then putting it back...


I.E.

dim sDate as date = now()
dim dBday as date= rs("date")
dim sBday = dBday.Month & "/" & dBday.Day & "/" & now.year
dbday = ctype(sbday,date)
if datediff(d,sdate,sbday) = 0 then ......

Probably got something slightly wrong as ther in no intellesence her and this is all from memory.. (yuk)

HTH

Rob


 
Ah yes I see how I should approach this situation. Thanks again for helping me out.

Manguilla
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top