/    Sign up×
Community /Pin to ProfileBookmark

PHP / SQL Dates

Hello,
I am trying to make a script that checks the database for members that expire in the next 60 days, then print their information.

I am not getting any errors but my results are strange. My date range is today (Sept 1 2009) and 60 days from now (Nov 1st 2009). Those 2 variables are set and they print correctly at the top of the results page (see below) but I am getting only 2 dates for expiring members – 1/31/2010 and 10/31/2009.

I know there are members in the DB with Sept and Nov expiration dates but they are not listed.

Code is below along with a sample of my results.

Thanks you for any ideas.

[CODE]<?php
// Set date and time
$today = date(“m/d/Y”);
$sixtydaysout = mktime(0, 0, 0, date(“m”)+2, date(“d”), date(“Y”));
$expiresoon = date(“m/d/Y”, $sixtydaysout);

print “Today is: $today <br/>”;
print “Sixty days from now is: $expiresoon <br/><br/>”;

$result = mysql_query(“SELECT * FROM members WHERE PAID_THRU BETWEEN ‘$today’ AND ‘$expiresoon’ LIMIT 1000″);
$row = mysql_fetch_array($result) or die(mysql_error());

while($row = mysql_fetch_array($result)) {
echo $row[‘FIRST_NAME’]. ” “. $row[‘LAST_NAME’]. “, “. $row[‘PAID_THRU’];
echo “<br/><br/>”;
}
?>[/CODE]

—–RESULTS PAGE—–

Today is: 09/01/2009 – ($today)
Sixty days from now is: 11/01/2009 ($expiresoon)

Tracey Lennemann, 1/31/2010

Patricia Brockhoff, 10/31/2009

Kimberly Melrose – Wyatt, 10/31/2009

Mary-Anne Ross, 10/31/2009

Michele Katila, 1/31/2010

Cheri Lyle, 1/31/2010

Heather Moser, 1/31/2010

Krystina Ash, 10/31/2009

Jill Barber, 1/31/2010

Andrea Salzl, 10/31/2009

Nicaise Moutin, 1/31/2010

Holly Boutin, 1/31/2010

Lisa Gibson, 10/31/2009

Janet Leslie, 10/31/2009

Ann Freimuth, 1/31/2010

Edie Shuman-Gibson, 1/31/2010

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@coreillySep 02.2009 — have you tried just using unix timestamps?
[CODE]<?php
// Set date and time
$today = date("U");
$expiresoon = $today + 5184000;//the number of seconds in 60 days

print "Today is: $today <br/>";
print "Sixty days from now is: $expiresoon <br/><br/>";

$result = mysql_query("SELECT * FROM members WHERE unix_timestamp(PAID_THRU) BETWEEN '$today' AND '$expiresoon' LIMIT 1000");
$row = mysql_fetch_array($result) or die(mysql_error());[/CODE]
Copy linkTweet thisAlerts:
@stackumhiauthorSep 02.2009 — Thanks coreilly,

I just tried your suggestion and it displayed no results.
Copy linkTweet thisAlerts:
@HanrattySep 04.2009 — $Header = $_POST['Header'];

$Yeargroup = $_
POST['Yeargroup'];

$Details = $_POST['Details'];

$Footer = $_
POST['Footer'];

$Deadline = $_POST['Deadline'];

$Date = $_
POST['Date'];


list($DD,$MM,$YY) = explode("/",$Date);

if(!checkdate($MM,$DD,$YY))

{

echo 'The date is invalid, please enter a date in the format

DD/MM/YY';

}else{

$Date = date('Y-m-d', strtotime($Date));

$Query="INSERT INTO bulletin (Header, YearGroup, Details, Deadline, Footer, Date)VALUES

('$Header','$Yeargroup','$Details','$Deadline','$Footer','$Date')";

mysql_query($Query) or die ('Error updating database');

printf ("Bulletin Item Added<br><br><br>Refreshing...");

}

?>
×

Success!

Help @stackumhi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...