Forum Moderators: coopster

Message Too Old, No Replies

Another Date Query.

PHP/ mysql date plus 6 months query

         

CRdeveloper

1:27 am on Aug 3, 2007 (gmt 0)

10+ Year Member



Hello,

May I ask for help with a query.

I need to send a scheduled email out to registered users, 6 months after their registration date. Therefore I need to create a file that I can cron.

I'm thinking "now" equals registered date plus 6 month...

Can someone translate that into a php/mysql database query. I would appreciate it.

-:)

jatar_k

3:07 am on Aug 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld CRdeveloper,

if you use mktime [php.net] to get your timestamp combined with strtotime [php.net] to add six months

then use strftime [php.net] to format it if you need something aside from a timestamp

then it should work just fine

Gian04

3:14 am on Aug 3, 2007 (gmt 0)

10+ Year Member



Try This

$currentdate = date("y-m-d");

$sixmonthsafter = date("y-m-d", strtotime($currentdate." + 6 months"));

$query_records = "SELECT * FROM table_here WHERE date_field >= '".$sixmonthsafter."'";
$records_result = mysql_query($query_records) or die(mysql_error());
if (mysql_num_rows($records_result) > 0) { // Means Result NOT Empty
while($row_records = mysql_fetch_row($records_result)) {
// Do whatever you want
}

}

[edited by: Gian04 at 3:15 am (utc) on Aug. 3, 2007]

StudioKraft

3:38 am on Aug 3, 2007 (gmt 0)

10+ Year Member



Would this work?

SELECT *
FROM `your_table`
WHERE NOW() >= DATE_ADD( registration_date, INTERVAL 180 DAY )

CRdeveloper

8:14 am on Aug 3, 2007 (gmt 0)

10+ Year Member



Thank you for the quick response. I will try your suggestions and post my results! Thanks for the support!