Link to home
Start Free TrialLog in
Avatar of Monte2256
Monte2256

asked on

Having a problem with date conversion in my php code

The coupon page has a startdate and and enddate to display coupons.  The information in the database is not stored as epoch. So I'm trying to convert it, but nothing has worked. see code below:  Thank you in advance

<?php 

    $query = "SELECT  ybgname, ybglink, ybglink2, ybgdate, enddate  FROM ybgcoupons ORDER BY ybgname";

    $result = mysql_query($query) or die('Sorry, No Coupons Available');

    while($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
	    $today = time();

        $ybgname = $row['ybgname'];

        $ybglink = $row['ybglink'];

        $ybglink2 = $row['ybglink2'];

		$fromdate = $row['ybgdate'];

		$todate = $row['enddate'];




if ($today>=$fromdate && $today<=$todate)
{
echo "<h4>$ybgname</h4> - $ybglink.'$string'.$ybglink2<br><br>";
}
else
{
    echo "Not in Date range<br> ";	

}
}
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please use var_dump() to print out the contents of $row and post that here so we can see the data, thanks.

And make sure you're using the ISO-8601 standard for dates, and that your columns are defined as DATE or DATETIME data types.

If you're new to PHP and want some good learning resources, this article can help you get a good foundation.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
Avatar of Monte2256
Monte2256

ASKER

int(1415149013) string(10) "2014-10-31" string(10) "2014-09-01"

I need to convert the last 2 dates to epoch i think.
Something is not right here.  The SELECT query gathered five columns, but the recent post only showed us three.  And since it was an associative array, there would have been named keys for the columns, right?

The SSCCE is an incredibly powerful and important concept in the process of asking questions and getting answers.  This is a data-dependent problem and it will be very easy to work out as soon as we see the data!

PHP strtotime() (as described in the article about date/time) converts date/time values to Unix timestamps.
Thank you I gave it to my programmer to review, it was beyond me.