/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Help with Date script

I have a website that allows people to post ads. Ads remain active for 30 days. In their control panel they can manage their ads, i.e., Edit, Delete, Renew, etc.

In this case I’m working with the “Renew” feature. I want to show how many days they have left before their ad becomes inactive.

When they submit an ad the date is recorded in the database using MySQL’s DATE function. (I’m not interested in the “time”, just the date). Here’s how I query the database and the code to do the above:

[code=php]$query = “SELECT DATE_FORMAT(submitted, ‘%m/%d/%y’) AS date FROM ads WHERE id=’$id'”;
$result = mysql_query($query) or trigger_error(“Query: $queryn<br>MySQL Error: ” . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$date = stripslashes($row[‘date’]);
}

$originaldate = $date; //any properly formated date
$ageindays = number_format(floor((date(“U”)-strtotime($originaldate))/86400),0);

//print $ageindays . ” days”;

$torenew = 30 – $ageindays;

echo ”
Date Posted: &nbsp;$date
<br><br>
Ads remain active for 30 days.
<br><br>
“;

if ($torenew <= ‘0’)
{
echo “<span style=’color:red’><strong>Ad Expired</strong></span>”;
}
else
{
echo “You will need to renew this ad in <span style=’color:red’><strong>$torenew</strong></span> days.”;
}[/code]

OK, it works. But it triggers this error message:

[code=php]date(): It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/New_York’ for ‘EST/-5.0/no DST’ instead[/code]

I tried using this:

[code=php]$ageindays = number_format(floor(date_default_timezone_set(‘America/Indianapolis’)-strtotime($originaldate))/86400),0);[/code]

But it gave the error:

[code=php]Parse error: syntax error, unexpected ‘,’ in /hsphere/local/home/davida261/elmorons.com/members/manage_ad.php on line 76 [/code]

That’s the comma in the above just behind the – 86400)

How can I correct this?

Thanks
Alan P

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@Alan_PauthorDec 03.2008 — OK, I got it working.
×

Success!

Help @Alan_P 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.17,
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,
)...