Solved

Having a problem with date conversion in my php code

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

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

Suggested Solutions

Title # Comments Views Activity
php call to a non-object 3 32
How do I put a session for a radio button? 4 12
Before I get too far.. best way to save dates data 4 15
MySqlDump not dumping triggers 1 17
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

911 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

23 Experts available now in Live!

Get 1:1 Help Now