473,462 Members | 1,350 Online
Bytes | Software Development & Data Engineering Community
Create 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 3592
>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
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()...
3
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...
0
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...
5
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...
3
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...
11
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...
1
by: sajithamol | last post by:
What is the difference between current_date & sysdate function?
5
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...
2
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...
2
by: ctje | last post by:
I have a project: Current_Date minus the end of the year.. How can i do this??
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.