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 %>
 
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!

???
 
I mean if i try and use the -2 bit of the command:

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

Kinda means going back in time?! (88 mph?!)
 

Sheco said:
How do you go back in time?
By doing the TimeWarp of course..

No, seriously - there's a guy you want to call - I think: E. Brown - that's it Dr. Emmett Brown.



A smile is worth a thousand kind words. So smile, it's easy! :)
 


Or you could just use DateDiff() ...

A smile is worth a thousand kind words. So smile, it's easy! :)
 

And CDate() will also help you out.

A smile is worth a thousand kind words. So smile, it's easy! :)
 

No problem, and if you crack that going back in time thing, remember who helped you... and post the code on these forums... ;-)

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Sheco said:
How do you go back in time?
It's just a jump to the left. (sorry couldn't resist)

make sure that you cast both variables as dates before comparing

Code:
if (cdate(strClose) = cdate(strMyDate)) then


Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 

:) You see Chris, that's what you need a time machine for.... Maybe Steve will lend you his when it's ready..

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Right ok, if I want to use an if statement to select:

IF (my date in the db) ADD 2 DAYS then send an email how would I do that?!

(excluding time machine jokes please!)[neutral]
 
I need an email to be sent when 2 days have passed the stored date....thoughts?
 
[tt]
RiffRaff = "d"
Magenta = 2
Columbia = rs("MyDateField")
Frankenfurter = DateAdd(RiffRaff, Magenta, Columbia)
Rocky = Date()
IF (Frankenfurter = Rocky) THEN
'Send Email Here
END IF
[/tt]
 
IF Datediff("d",GetDate(),mydbdate)=2 then
'send email
end if

-DNG

 
Oh, if 2 days have passed then use >= instead of =
[tt]IF (Frankenfurter >= Rocky) THEN[/tt]

Also do you want to send the message every time the page is loaded for this particular date or just once?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top