Solved

PHP - Spot the Error

Posted on 2011-03-25
4
198 Views
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,cm.name,log.message,log.LOGSTAMP
From admin_log log, client_master cm 
Where 
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') 
AND 
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

0
Comment
Question by:codemonkey2480
4 Comments
 
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
0
 
LVL 83

Accepted Solution

by:
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:

24.03.2011
24.03.2011:18:00:00','DD.MM.YYYY:HH24:MI:SS')
25.03.2011:14:19:00','DD.MM.YYYY:HH24:MI:SS')

Where is your error coming from?

http://us2.php.net/manual/en/function.date.php .

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php 
$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')";

 ?>
</body>
</html>

Open in new window

0
 

Author Comment

by:codemonkey2480
ID: 35219314
Let me take  look.
0
 
LVL 5

Expert Comment

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

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

810 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