Solved

Having a problem with date conversion in my php code

Posted on 2014-11-04
6
47 Views
Last Modified: 2016-05-25
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

0
Comment
Question by:Monte2256
  • 3
  • 2
6 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40422586
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40422592
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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0
 

Author Comment

by:Monte2256
ID: 40423085
int(1415149013) string(10) "2014-10-31" string(10) "2014-09-01"

I need to convert the last 2 dates to epoch i think.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40423125
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.
0
 

Author Comment

by:Monte2256
ID: 40429182
Thank you I gave it to my programmer to review, it was beyond me.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question