PHP - Spot the Error

Posted on 2011-03-25
Last Modified: 2012-05-11
Whats wrong with this query? I get an error "invalid month"

$yesterday = mktime(0, 0, 0, date('m'), date('d')-1,   date('Y')); // determin what yesterday was
$now = time();
Also how do I find out the issue?
$yesterday = mktime(0, 0, 0, date('m'), date('d')-1,   date('Y')); // determin what yesterday was
		$now = time();

	$reports_sql = "Select log.clientid,,log.message,log.LOGSTAMP
From admin_log log, client_master cm 
log.clientid=cm.clientid AND
log.logstamp >= TO_TIMESTAMP('".date('d', $yesterday).".".date('m', $yesterday).".".date('Y', $yesterday).":18:00:00','DD.MM.YYYY:HH24:MI:SS') 
log.logstamp < TO_TIMESTAMP('".date('d', $now).".".date('m', $now).".".date('Y', $now).":".date('H', $now).":".date('i', $now).":00','DD.MM.YYYY:HH24:MI:SS')
Order by ClientId";

Open in new window

Question by:codemonkey2480
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35218401
I'm not sure if that shouldn't be
'".date('d', $yesterday)."-".date('m', $yesterday)."-".date('Y', $yesterday)." 18:00:00'
(- instead of . like in a date 03-25-2011 18:00
LVL 83

Accepted Solution

Dave Baldwin earned 500 total points
ID: 35218679
Looks to me like it's producing the correct values.  Here I've converted your code to just display the results. I get:


Where is your error coming from? .

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

$yesterday = mktime(0, 0, 0, date('m'), date('d')-1,   date('Y')); // determin what yesterday was
$now = time();
echo date("d.m.Y",$yesterday)."<br>";
echo date('d', $yesterday).".".date('m', $yesterday).".".date('Y', $yesterday).":18:00:00','DD.MM.YYYY:HH24:MI:SS')" ;
echo "<br>";
echo date('d', $now).".".date('m', $now).".".date('Y', $now).":".date('H', $now).":".date('i',$now).":00','DD.MM.YYYY:HH24:MI:SS')";


Open in new window


Author Comment

ID: 35219314
Let me take  look.

Expert Comment

ID: 35220036
SELECT log.clientid,,log.message,log.logstamp
FROM admin_log log, client_master cm 
    log.clientid = cm.clientid
    log.logstamp >= CURRENT_TIMESTAMP  - INTERVAL 1 DAY
ORDER BY log.clientid

Open in new window


Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
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…

632 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