Solved

Having a problem with date conversion in my php code

Posted on 2014-11-04
6
42 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 108

Accepted Solution

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

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 108

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now