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

Date command

Status
Not open for further replies.

stevemarsh99

Technical User
Aug 10, 2005
88
GB
Hey guys and girls,

i have a page that runs an IF statement to send an email. great, but now I want the if statment to run IF todays MINUS 2 DAYS is equal to a date in a database?

i have it working with if todays date ADDED ONE DAY (tomorrow basically) is equal to my db date, but if i go back in time it runs the statment even if the date is tomorrow!

here is my code:

<%
strToday = dateadd("d", date(), 1)
strClose = dateadd("d", date(), -2)
strMyDate = (rs_ealert.Fields.Item("MAGDATE").Value)
%>________________________

____________________________
<%
if strClose = strMyDate then
%>
<%
FormFields = "to~body~subject"

Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.From = "dfs@sdf.com"
objCDO.To = (rs_ealert.Fields.Item("MAGDATE_CONTACT").Value)
objCDO.Cc = ""
objCDO.Bcc = ""
objCDO.Subject = "blah"
BodyString = "text goes here"


objCDO.Body = BodyString
objCDO.BodyFormat = 0
objCDO.MailFormat = 0
objCDO.Send
Set objCDO = Nothing %>

<% else %>
<% Response.Write("") %>
<% end if %>
 
In this case you may want to send the email

if dbstoreddate + 2days = today
send email

end if

That would make it much easier.

Cheers

QatQat

Life is what happens when you are making other plans.
 


Code:
if datediff("d",date(), cdate(rs_ealert.Fields.Item("MAGDATE").Value))  = -2 then
'send mail
end if

if it is definitely equal to 2 days ago then the above applies, else use <= for anything over 2 days ago (e.g. 3, 4 etc)

A smile is worth a thousand kind words. So smile, it's easy! :)
 
According to the link, the second and third arguments are swapped in the first post:
-------------------
DateAdd Function
Returns a date to which a specified time interval has been added.

[tt]DateAdd(interval, number, date)[/tt]
Arguments
interval
Required. String expression that is the interval you want to add. See Settings section for values.
number
Required. Numeric expression that is the number of interval you want to add. The numeric expression can either be positive, for dates in the future, or negative, for dates in the past.
date
Required. Variant or literal representing the date to which interval is added.
 
Guys I have this code on a repeat region, and it sends an email as many times as there are records. Basically this does not work:

<% Days = "d"
Difference = 2
SAARASDATE = (rs_ealert.Fields.Item("MAGDATE").Value)
Frankenfurter = DateAdd(Days, Difference, SAARASDATE)
Rocky = Date()%>


<% IF (Frankenfurter >= Rocky) THEN %><br>
<%
FormFields = "to~body~subject"

Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.From = "fdg@fdg.com"
objCDO.To = (rs_ealert.Fields.Item("MAGDATE_CONTACT").Value)
objCDO.Cc = ""
objCDO.Bcc = ""
objCDO.Subject = "fdg Workflow Reminder"
BodyString = "dfgfdgfdgfdg"


objCDO.Body = BodyString
objCDO.BodyFormat = 0
objCDO.MailFormat = 0
objCDO.Send
Set objCDO = Nothing %>
<% END IF %>
 
I would suggest just using something like this:

IF Datediff("d",GetDate(),mydbdate)=2 then
'send email
end if

damber, also suggested something similar...so u can use either of these...

-DNG
 
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'GetDate'
/ealert/email_sending_page.asp, line 96

EEk?
 
For debugging purposes, try adding the values in your emails... just to make sure they are not >=
[tt]
BodyString = "Frankenfurter = " & Frankenfurter & vbCrLf _
& "Rocky = " & Rocky & vbCrLf
[/tt]
 


Steve,

If you are wanting to send an email to a selected list of users retrieved from a database, then you probably need to do it differently...

change your SQL statement to use a WHERE clause that selects based on the current date and the date in the database. Which database are you using: SQL Server, Access, MySQL, Oracle, other ?

Then you can cycle through all the records in your ASP page, without the checks.

BTW DNG, getDate() is SQL Server not ASP.

Oh, and please.... change your var names, my brain is beginning to hurt....


A smile is worth a thousand kind words. So smile, it's easy! :)
 
right i have this much and it still repeats the all the records in the db and sends out emails. I have emails hardcoded in the db so its doesnt matter (Access)

thoughts??

<% IF Datediff("d",Date(),(rs_ealert.Fields.Item("MAGDATE").Value))>=2 then %>

STILL NO JOY!

(I have ONE record in the db that is the 02/12/2005, the rest are the 10/12/2005...so why lord why!!)
 
what happens if you put both values into your email message? Perhaps we are barking up the wrong tree.

For example:
If date1 refers to a later point in time than date2, the DateDiff function returns a negative number.

If your server date format is dd/mm/yy then those dates would give you large negative numbers because they are for February and December.

 

try this for the ASP solution...:

<% IF Datediff("d",Date(),(rs_ealert.Fields.Item("MAGDATE").Value))<=-2 then %>

Also, what Sheco is saying is that US and UK dates are different (US=mm/dd/yyyy - UK=dd/mm/yyyy) so this could impact if your database is setup as one and the webserver another.

You should still look to selecting this from the database - in access:

SELECT email_address
FROM yourtable
WHERE yourtable.some_date <= (Date()-2)

This will then return back any email addresses where the date is older than (or equal to) 2 days ago.

Then you don't need to check in ASP as the recordset has all the emails you need to send.

-- you may use the recordset for something else.. if you do then this may not be an option.. but don't select records you're not going to use.




A smile is worth a thousand kind words. So smile, it's easy! :)
 
No guys I mean I would like to SEND AN EMAIL based on a date in a database. for eg:

05/12/2005......2DAYS after i would like an email sent to someone.. (hardcoded)

Shed any light?
 
YEAH IT WORKS>>>>GREAT WORK GUYS>>>>THIS LINE DID THE BUSINESS!

<% IF Datediff("d",Date(),(rs_ealert.Fields.Item("MAGDATE").Value))<=-2 then %>

hats off to ye!
 

Glad it worked out for you... you should still look into the database method, it will be much more efficient when the number of entries/email addresses increase.



A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top