Solved

Having a problem with date conversion in my php code

Posted on 2014-11-04
6
50 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 110

Accepted Solution

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

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 110

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

749 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