473,799 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

current_date()-1 misbehaving on first day of month

Hello,

PHP and mysql

I have the following select statement whch gives me a count for
downloads for previous day.

SELECT
COUNT(swid)
FROM
downloads
WHERE
date = current_date()-1

This works on every day of the month except the 1st day....so on 1st
November my values for 31 Oct showed 0 even though elsewhere I could see
that there was activity. It was the same on 1 Oct for 30th Sept and
will be no doubt the same on 1st Dec for 30 Nov.

Any ideas on why it shows zero? Does current_date()-1 have problems
when it's the first day of month?

Thanks,

td.
Great news!
Cure found for Bird Flu!
http://www.pocketpcheaven.com/birdflue.php
Nov 2 '05 #1
2 3613
>I have the following select statement whch gives me a count for
downloads for previous day.

SELECT
COUNT(swid)
FROM
downloads
WHERE
date = current_date()-1 ^^^^^^^^^^^^^^^ ^^^^^^^^
This isn't a reasonable way to do date math.
This works on every day of the month except the 1st day....so on 1st
November my values for 31 Oct showed 0 even though elsewhere I could see
that there was activity.
Try running:

select current_date()-40;

and observe that it makes sense on *NO* days of the month.
It's doing INTEGER, not DATE, math.

Then try:
select subdate(current _date(), INTERVAL 40 DAY);
It was the same on 1 Oct for 30th Sept and
will be no doubt the same on 1st Dec for 30 Nov.

Any ideas on why it shows zero? Does current_date()-1 have problems
when it's the first day of month?


current_date()-1 makes about as much sense as current_date()/2.583
(none at all). It's a coding error regardless of what day of the
month it is. Even a stopped clock is sometimes right.

Learn about adddate() and subdate().

Gordon L. Burditt
Nov 2 '05 #2
toedipper wrote:
I have the following select statement whch gives me a count for
downloads for previous day.

SELECT
COUNT(swid)
FROM
downloads
WHERE
date = current_date()-1


Hi toedipper,

I think you're looking for something like this instead:

SELECT CURRENT_DATE() - INTERVAL 1 DAY;

HTH.
Peter.
--
http://www.phpforums.nl
Nov 2 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
10084
by: toedipper | last post by:
Hello, I have the following section of php code which updates a mysql record from a form. For the values of livedate and livetime I need to insert the current_date() and current_time() respectively. When I run the code however it falls over at the line with GetSQLValueString(current_date(), "date")
3
7884
by: Jonathan | last post by:
Hi all! For a match schedule I would like to find all possible combinations of teams playing home and away (without teams playing to themselves of course). I now the simple version works something like this: For a (very) simple table containing three rows like this: row 1: A
0
1281
by: btober | last post by:
/* I have a customer requirement to provide for flexibility on how vacation leave is calculated and am having trouble with executing the necessary SQL which is stored in the database as a text column. The employee table and a newly minted vacation leave formula table, shown below, are related and identify what vacation leave calculation is used for each employee (there are three different formulas for calculating vacation leave). */
5
5557
by: Miquel van Smoorenburg | last post by:
I have a database with a btree index on the 'removed' field, which is of type 'date'. However it isn't being used: techdb2=> explain select * from lines where removed > CURRENT_DATE; QUERY PLAN ------------------------------------------------------------ Seq Scan on lines (cost=0.00..243.47 rows=2189 width=324) Filter: (removed > ('now'::text)::date) (2 rows)
3
2040
by: Chifo | last post by:
hello. i have a problem with a populate html table with data from table here it's the problem two querys retrieving data from table, one of querys show me a colletion of data from 6:00 am to 15:30 pm timestampz, i put this on a part of html table. when time on my if condition es great than 15:31, showme data from 15:31 to 23:59 timestamp and populate another part of html table. but, data in html first part,it's gone away.
11
9835
by: sayamishiraj | last post by:
i am using vb 6 and postgresql as the back end. when running the function in the vb , it shows the error message of odbc call failed. but when i run the same function in the postgresql then it runs easily. can anyone suggest how can i increase the execution time in the odbc since the database is too huge,
1
5766
by: sajithamol | last post by:
What is the difference between current_date & sysdate function?
5
4657
by: tao | last post by:
Hi, I meet some problem in debugging php files. this is the one running smoothly $query = "select account.id as account_id from account where (date(creationdate)=date(current_date-interval '1 days') or account.status='DELETED'); but when I changed the condition to: if ($result_array != date(current_date-interval '1 days')) {
2
4683
by: apollock | last post by:
Our application is having an issue where a query in a stored procedure periodically gets a bad plan with a Lazy Spool Operator that changes the query execution time from 5ms to 900ms and kills our CPU. We are running x64 SQL 2005 SP2 on Windows 2003 SP2. We thought it might be parameter sniffing that was causing the bad plan, so we re-wrote the query to disable parameter sniffing. Unfortunately, that made the problem worse as we always...
2
1238
by: ctje | last post by:
I have a project: Current_Date minus the end of the year.. How can i do this??
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.