Forums
This topic is locked
Date Compare and email
Posted 21 May 2007 04:50:37
1
has voted
21 May 2007 04:50:37 steve copelin posted:
Just looking for a bit of help.I'm working on a php script that will run on a daily basis and compare the current day/month/year and compare that to a stored(db) field, then out put the result to an e-mail.
$startdate = strtotime($row["startdate"]);
$todaydate = strtotime ("now"
This is where i get stuck, i need to get an output that will compare the two variables and minus 1 month from the "now" date.
I'll explain what i need to, it might make it easier to answer.
I have a date in my database that points out when an account was created, the above script needs to check all the records and email me 1 month before the account is due.
Steve
Replies
Replied 21 May 2007 06:00:47
21 May 2007 06:00:47 steve copelin replied:
I think i may have worked it out, but not too sure about security. I was planning to use a cron entry to drive the script. Having my database password in the script, is that a security exploit?
db connect info, blah,blah,blah
$minusthirtydays = mktime() -2592000;
SELECT * FROM 'table' WHERE 'startdate' > $minusthirtydays;
mmmm, now i'm confusing myself.
S
db connect info, blah,blah,blah
$minusthirtydays = mktime() -2592000;
SELECT * FROM 'table' WHERE 'startdate' > $minusthirtydays;
mmmm, now i'm confusing myself.
S
Replied 21 May 2007 18:22:51
21 May 2007 18:22:51 Alan C replied:
HI
those dates and times are really confusing in mysql, I've found the easiest way to handle them is either . . .
convert the dates and times to unix timestamps - that's seconds since 1 Jane 1970 and store that - the number range allows you to store dates up to about 2035, long enought for most things. Then the date arithmetic becomes very easy.
Second way - there are mysql functions that add / subtract time, here's part of a query that adds time (there was a lot more that was not copied)
<pre id=code><font face=courier size=2 id=code> "UPDATE properties SET p_expiry_date=%s, p_entry_type=%s WHERE p_id=%s",
'DATE_ADD(NOW(), INTERVAL '.ENHANCED_TRIAL_DAYS.' DAY)'</font id=code></pre id=code>
what I like to do with constants like ENHANCED_TRIAL_DAYS is keep them in a separate file, constants.php and then have an include at the top of each file that needs them, that way it's easy to change them. I do the same with the database details - keep them in a connection file like dw does.
There is a good login system at www.evolt.org that has some date math about when users are logged in, if you want some starting code to pick apart it's a useful place. Look on the left-hand side for php login system.
those dates and times are really confusing in mysql, I've found the easiest way to handle them is either . . .
convert the dates and times to unix timestamps - that's seconds since 1 Jane 1970 and store that - the number range allows you to store dates up to about 2035, long enought for most things. Then the date arithmetic becomes very easy.
Second way - there are mysql functions that add / subtract time, here's part of a query that adds time (there was a lot more that was not copied)
<pre id=code><font face=courier size=2 id=code> "UPDATE properties SET p_expiry_date=%s, p_entry_type=%s WHERE p_id=%s",
'DATE_ADD(NOW(), INTERVAL '.ENHANCED_TRIAL_DAYS.' DAY)'</font id=code></pre id=code>
what I like to do with constants like ENHANCED_TRIAL_DAYS is keep them in a separate file, constants.php and then have an include at the top of each file that needs them, that way it's easy to change them. I do the same with the database details - keep them in a connection file like dw does.
There is a good login system at www.evolt.org that has some date math about when users are logged in, if you want some starting code to pick apart it's a useful place. Look on the left-hand side for php login system.